cancel
Showing results for 
Search instead for 
Did you mean: 

How to Zip pdf files in XSJS

0 Kudos

I want to Zip pdf files (which are stored in a table as blob objects) and return it to the UI5 application.

Accepted Solutions (1)

Accepted Solutions (1)

pfefferf
Active Contributor
0 Kudos

In XS Classic you can use the $.util.Zip library. In the XSJS compatibility mode of XS Advanced you can use that library too, but there are more better Node alternatives. But according to your other questions here I think you are working with XSc.

0 Kudos

Hi Florian,
I am trying to do something like this:

query: select document,title from table where id in [1,2,3..];

var zip =new $.util.Zip();

var folderName="test";

while(resultSet.next()){

zip[folderName+"/"+resultSet.getString(2)+".pdf"]=resultSet.getBlob(1);
}

$.response.setBody(zip);

$.response.setContentType("application/zip");

(Its not the complete code but I am doing something like this)

I want the output to be of something like below: my zip folder contains a folder "test" which contains my "pdf" files.

But when I open the generated zip it displays Invalid zip format. I don't think that pdf's are being zipped inside a folder. Am I missing something?

pfefferf
Active Contributor
0 Kudos

Can you show your whole coding which is related to the zip file creation. What I miss is that you set the body of the response as array buffer of the zip object.

The settings regarding the "folder creation" look ok.

Maybe you try to replace the setting of the PDF blob to the zip by a simple string to test in a first step if the zipping in general works. Then it can be checked by the blob value is probably not correctly zipped.

0 Kudos

Thanks Florian. Actually I encoded my variable to base64 before zipping, so that's the reason why it was displaying invalid format.

0 Kudos

And Im using XSA not XSc

Answers (0)