Streaming XML data to ZipFile Write - how to set internal filename

I would like to stream data directly to a zip file (without first writing the data to disk).
I want to dynamically set the name of the file inside the zip file (not the zip file, but the file it contains).
Given this file:
mydata.zip
myfile1.xml

I want to create mydata.zip file (which I can do and name properly), and name the internal xml file without first writing the xml to disk.

When I use the XML formatter, it creates output as output0, not as myfile1.xml.

If I read a file from disk, it correctly sets the file name, however if I use the XML formatter to create binary data to stream to the ZipFile Write component, I can’t find a way to set XML filename.

Any suggestions are greatly appreciated.
Thanks,
Judy

@jcampion, I think you’re almost there. With the ZipFile Write snap, make sure to check the Use input view label option. Then in the views tab, give the input view the name of the internal filename you would like.



@jcampion, Here is a way, if you want to set filename dynamically.

I am not sure about your pipeline design, But zip write always takes binary input. Place a mapper before document to binary snap and set “$[‘content-location’]” property with filename you want. that’s it :slight_smile:.

Design:

Output:

hope this helps.

Thank you so much. It worked!

Hi,

I already have a xml file and I wanted to zip this xml file. Can you suggest how to do , the above method is not working for me. I use below snaps

file Reader -> XML Parser -> Mapper -> Document to Binary -> Zip File writer

in mapper I m not able to set values against content ,content location due to which document to binary snap error out.


Please suggest , i m stuck in it

Are you wanting to put the file in the Zip in the XML format? Since you used the XML Parser with the Document To Binary, you’re effectively turning it into JSON. You probably don’t want that.

The ZipFile Writer will get the name for the file in the zip from the ‘content-location’ property in the binary document header. The FileReader will add this property to the header, so the name of the file in the zip should be the same as where it was read from.