Page 1 of 1

How to create a zip file of a folder, server side?

PostPosted: Thu Jun 21, 2018 6:50 pm
by pbdavis
I'm creating multiple PDF reports and I need to zip these up to download as a single file using the Web client. I'm using the IT2BE Data Plug-in to create the PDF files and have these saved on the server in a new folder I create for each request by the user for reports. I've looked at IT2BE's Tools plug-in for zip but reading the documentation it looks like this only works client-side. I've looked at JSZip but I don't know how I could use this in Servoy. Does anyone know how to zip up a server folder in Servoy? Example code would be great.

Thanks,
~Paul

Re: How to create a zip file of a folder, server side?

PostPosted: Fri Jun 22, 2018 3:38 pm
by rgansevles
I expect you can zip the files using IT2BE tools plugin and then serve the result using plugins.file.writeFile() which streams to the client for Web/NG,
see https://wiki.servoy.com/display/DOCS/file

Rob

Re: How to create a zip file of a folder, server side?

PostPosted: Fri Jun 22, 2018 7:41 pm
by pbdavis
All the examples only show using IT2BE Tools plugin zipping client side. I have the downloading of files working. I have a ticket in to IT2BE to ask if their zip() works server side.

Re: How to create a zip file of a folder, server side?

PostPosted: Mon Jun 25, 2018 5:08 pm
by pbdavis
IT2BE confirmed their Tools plug-in only works client side with Web Client. Anyone have a way to zip files server side using the Web Client?

Re: How to create a zip file of a folder, server side?

PostPosted: Tue Jun 26, 2018 12:20 am
by mboegem
Hi Paul,

I had a quick look into some plugins/code and I think the solution isn't very straightforward.
Webclient needs to work with remote files, which isn't supported in this way.

But there's a workaround for this: use some kind of headless client.
Headless clients run serverside but can execute 'client' code.
You can launch a headless client on the fly, by using the headless client plugin which is shipped with Servoy by default.
(https://wiki.servoy.com/display/DOCS/headlessclient)

The other way using a headless client is by creating a solution acting like a RESTful webservice. (https://wiki.servoy.com/display/DOCS/RE ... b+Services)
From the web client you just do the request to this webservice, which can then run your code and even return the zipped file, as you like.

Although code for either of the solutions to create your zipfile will be quite similar, I think my choice would be the RESTful webservice.
Using headless client you have to deal with an async process, it'll also take a bit more code to handle the launch and shutdown nicely.
The RESTful 'client' will just launch itself when requested and will sit in the background waiting for new requests, re-use of the same client works out of the box.

Both solutions take a bit more than sample code to get it working, but I think the links I mentioned will give you a nice idea.

Re: How to create a zip file of a folder, server side?

PostPosted: Tue Jun 26, 2018 8:08 pm
by pbdavis
Hi Marc,

Thanks for the suggestions. I will look into both of these options. BTW, IT2BE did mention that their Tools plug-in would work server side with a headless client.

Re: How to create a zip file of a folder, server side?

PostPosted: Wed Jun 27, 2018 1:31 am
by patrick
You could also have a look at svyUtils (https://github.com/Servoy/svyUtils) or via the web package manager‘s solutions tab. It has a method to zip files or folders in I think the svyIO scope.

Re: How to create a zip file of a folder, server side?

PostPosted: Wed Jun 27, 2018 6:42 pm
by mboegem
pbdavis wrote:IT2BE did mention that their Tools plug-in would work server side with a headless client.

I know :wink:

patrick wrote:You could also have a look at svyUtils (https://github.com/Servoy/svyUtils) or via the web package manager‘s solutions tab. It has a method to zip files or folders in I think the svyIO scope.

@Patrick: I don't think this will work, since it doesn't use remoteFile functions of the file plugin. AFAIK you will need that for the web client.

Re: How to create a zip file of a folder, server side?

PostPosted: Thu Jun 28, 2018 11:30 am
by rafig
I am using headless client to ZIP up a bunch of Excel files (also created by same headless client) & it works fine (however it would be great if it allowed you to add a password to the ZIP file).
Rafi

Re: How to create a zip file of a folder, server side?

PostPosted: Thu Jun 28, 2018 5:34 pm
by sean
@Patrick: I don't think this will work, since it doesn't use remoteFile functions of the file plugin. AFAIK you will need that for the web client.


Hi Marc, if I understand correctly, this is for WebClient. Remote files are really for smart client, because then the runtime is really on a different filesystem. In web clients, everything is relative to the server machine. Regular JSFiles and svyUtils zip functionality should work fine.

@Rafi, please consider filing a feature request for this. Although, this is really just pw-based encryption, which can be managed with the svyUtils cryto extesion

Examples also on demo.servoy.com

Re: How to create a zip file of a folder, server side?

PostPosted: Fri Jun 29, 2018 11:15 am
by rafig
sean wrote:@Rafi, please consider filing a feature request for this. Although, this is really just pw-based encryption, which can be managed with the svyUtils cryto extesion

Hi Sean,
I should have clarified that I was using the IT2Be Tools plug-in to do the ZIPping, not svyUtils, so I'd have to put in a feature request with them ;-)
I'm not sure how I could use the Crypto extension to help, unless it's to encrypt each file before putting in the ZIP file & having to decrypt on UNZIP...
Thanks
Rafi

Re: How to create a zip file of a folder, server side?

PostPosted: Fri Jun 29, 2018 1:26 pm
by sean
You could just encrypt the zip file
Something like:

Code: Select all
var zipFile = scopes.svyIO.zip(myFile);

// encryption options
var options = scopes.svyCrypto.createOptions().setAlgorithmName(scopes.svyCrypto.ALGORITHM_NAMES.AES);

// encrypt zip (As b64-encoded string. Decode to get bytes and write file)
var protectedZip = scopes.svyCrypto.encrypt(zipFile.getBytes(),options,myPassword);