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

Questions and answers on designing your Servoy solutions, database modelling and other 'how do I do this' that don't fit in any of the other categories

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

Postby pbdavis » Thu Jun 21, 2018 6:50 pm

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
Paul Davis
Belcan Engineering Group, LLC
pbdavis
 
Posts: 60
Joined: Thu Nov 30, 2017 5:40 pm
Location: Florida, USA

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

Postby rgansevles » Fri Jun 22, 2018 3:38 pm

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
Rob Gansevles
Servoy
User avatar
rgansevles
 
Posts: 1927
Joined: Wed Nov 15, 2006 6:17 pm
Location: Amersfoort, NL

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

Postby pbdavis » Fri Jun 22, 2018 7:41 pm

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.
Paul Davis
Belcan Engineering Group, LLC
pbdavis
 
Posts: 60
Joined: Thu Nov 30, 2017 5:40 pm
Location: Florida, USA

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

Postby pbdavis » Mon Jun 25, 2018 5:08 pm

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?
Paul Davis
Belcan Engineering Group, LLC
pbdavis
 
Posts: 60
Joined: Thu Nov 30, 2017 5:40 pm
Location: Florida, USA

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

Postby mboegem » Tue Jun 26, 2018 12:20 am

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.
Marc Boegem
Solutiative / JBS Group, Partner
• Servoy Certified Developer
• Servoy Valued Professional
• Freelance Developer

Image

Partner of Tower - The most powerful Git client for Mac and Windows
User avatar
mboegem
 
Posts: 1742
Joined: Sun Oct 14, 2007 1:34 pm
Location: Amsterdam

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

Postby pbdavis » Tue Jun 26, 2018 8:08 pm

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.
Paul Davis
Belcan Engineering Group, LLC
pbdavis
 
Posts: 60
Joined: Thu Nov 30, 2017 5:40 pm
Location: Florida, USA

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

Postby patrick » Wed Jun 27, 2018 1:31 am

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 Ruhsert
Servoy DACH
patrick
 
Posts: 3703
Joined: Wed Jun 11, 2003 10:33 am
Location: Munich, Germany

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

Postby mboegem » Wed Jun 27, 2018 6:42 pm

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.
Marc Boegem
Solutiative / JBS Group, Partner
• Servoy Certified Developer
• Servoy Valued Professional
• Freelance Developer

Image

Partner of Tower - The most powerful Git client for Mac and Windows
User avatar
mboegem
 
Posts: 1742
Joined: Sun Oct 14, 2007 1:34 pm
Location: Amsterdam

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

Postby rafig » Thu Jun 28, 2018 11:30 am

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
Servoy Certified Developer
Image
rafig
 
Posts: 704
Joined: Mon Dec 22, 2003 12:58 pm
Location: Watford, UK

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

Postby sean » Thu Jun 28, 2018 5:34 pm

@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
Software Engineer
Servoy USA
sean
 
Posts: 370
Joined: Mon May 21, 2007 6:26 pm
Location: USA

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

Postby rafig » Fri Jun 29, 2018 11:15 am

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
Servoy Certified Developer
Image
rafig
 
Posts: 704
Joined: Mon Dec 22, 2003 12:58 pm
Location: Watford, UK

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

Postby sean » Fri Jun 29, 2018 1:26 pm

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);
Software Engineer
Servoy USA
sean
 
Posts: 370
Joined: Mon May 21, 2007 6:26 pm
Location: USA


Return to Programming with Servoy

Who is online

Users browsing this forum: No registered users and 12 guests