Zip file write snap creating zip file with source folder structure , how to avoid file structure

Hi Team,

I am just reading the file from source location and writing the zip file in sldb, but it is creating the zip file with source structure when i unzip.

source file path is : /home/data/interface/inbound/filename.txt
when I unzip it, it has folder structure. here expectation is the zip file should have only file not file location structure

image

Hi @kkishore,

Place a Mapper between those two snaps and change the $['content-location'] header and be sure to select the 'Pass through' option in the Mapper.

Expression: $['content-location'].split("/")[$['content-location'].split("/").length - 1]
Target path: $['content-location']

image

This will remove the folder structure in the zip file.

1 Like

@j.angelevski ,

Thanks for the response, I will try and let you know the results

@kkishore,

The Mapper snap supports Binary Input/Output, you just need to select it from the Views tab in the Mapper.

@j.angelevski ,

I got it, thank you very much.

@j.angelevski ,

Thanks for the great support, It is working fine(removed folder structure), but i noticed one thing is when unzipped file the file is created like textbook…bin(inside the zip file).
expected file name is textbook.

it was there when created zip file with folder structure(source file path) also

image

@kkishore,

Can you provide the output of the file reader ? Or just show me the content-location header.

@j.angelevski ,

Please find the here,

@kkishore,

Sorry, but can you provide the x-amz-meta-mimetype header also ? If this is a .txt file try opening the file with Notepad to see if it opens and displays the data is it should.

@j.angelevski ,

File reader doesn’t show any x-amz-meta-mimetype when i validated.
I shared all the content showing by file reader in the screen shot earlier post

@kkishore,

And what type of file is this ? Is it .txt or something else ? What type of file are you reading ? What’s the content-type in the sftp server ?

@j.angelevski ,

There is no extension for the file in the source system(reading file from source using file reader through sftp ). it is not txt file,but we can open with notepad or textpad
sample file name is : xyzdata

@kkishore,

I’m not really sure why it adds the …bin after the filename. Can you check the output after the Mapper and see if some extension is added unintentionally ?

@j.angelevski ,

there is no extension after the mapper.it is just file name .

screen shot below

I think the problem is that the ZipFile Writer , automatically detects that the incoming file has a binary structure, and adds .bin at the end. You can try and add a custom content-type header in the mapper, along with the content-location:

@kkishore,

You can try changing the content-type header as Bojan suggested, but what I found is if I change the content-type header to application/octet-stream just like in your case, it automatically adds the ..bin extension to the file, so what I did is change the header to binary/octet-stream and this removed the extension.

@j.angelevski ,@bojanvelevski,

Thank you , it is working…great