Downloading binary files in a zip file


#1

Enonic version: Enonic XP 6.14.1
OS: Windows 10

Hi guys,

I have a list of binary files in a repository and i would like to download a group on them in a zip file. Could someone advise an easy way to do it?

Kind regards.


#2

Well, if you have access to the repository, couldn’t you simply export it with Toolbox and copy the files manually?


#3

Hi Jonas,

It’s part of an app where the user download data from the server using an interface. I think it’s not a good practice to let users access the server to download data manually hehehe.

Regards.


#4

Ah, I see.

Then, I would use Java for this. Java 8 comes with zip utilities included as standard, so you should be able to use this to create a zip file with the binaries you want to include.

There exists a JS implementation you could try, JSzip. However, I would be surprised if it doesn’t have some browser dependency that Nashorn doesn’t support.


#5

Thanks a lot for the advise Jonas. I will check JSzip library as I’m a C# developer.


#6

Hi again,

Do you know how to import a external library in a controller? I tried with require("/assets/js/zip/jszip.min.js")

but i fails and I’m not sure if it has to be imported in a different way


#7

The easiest way I know to import an external JS-library into the back-end is to import it as a webjar. Fortunately, jszip is available as a webjar, so you can simply add

webjar 'org.webjars:jszip:3.1.0'

to your dependencies in the build.gradle file to get the library into your project.

That being said. As expected, jszip fails due to some dependency not expecting to be run outside of a browser or the V8 engine. I get a TypeError: Cannot read property “document” from undefined in the dependency core-js.


#8

Thanks for your help. I got the same error. So it seems that if I want to use JSzip the only way is using Java.


#9