简体   繁体   English

zip 文件并从客户端或服务器下载?

[英]zip file and download from client or server?

I need to pull a set of arrays, they have values like ' http://example.com/1.png ' and I have to zip and download them when a user click 'download' on the cilent side.我需要提取一组数组,它​​们的值类似于“ http://example.com/1.png ”,当用户在客户端单击“下载”时,我必须压缩并下载它们。

For that part should I do it on server or client side?对于那部分,我应该在服务器端还是客户端做? I found few npm that can do the job but I doubt it should be at the server side, since I can pass my data from db to cilent.我发现很少有 npm 可以完成这项工作,但我怀疑它应该在服务器端,因为我可以将数据从 db 传递到 cilent。

For Server Side: 对于服务器端:

First You Can Make Use Of A NPM Module Called ADMZIP; 首先,您可以使用称为ADMZIP的NPM模块; And Pack The ZIP TO ADMZIP Object in nodejs side. 并在nodejs端打包ZIP TO ADMZIP对象。 And Send The Content in response From The Server Side Using ExpressJS(sendFile or download) 并使用ExpressJS从服务器端发送响应内容(sendFile或下载)

For Client Side: 对于客户端:

You Can Create A BLOB On The Client Side And Retrieve The Response And Then Download The Content 您可以在客户端创建BLOB并检索响应然后下载内容

Downloading and saving files from server using AngularJS 使用AngularJS从服务器下载和保存文件

In the case of zipping files on a frontend(using jszip for example) client probably will download images faster because most modern browsers can have 6 downloads at the same time, but on another hand, it has it's own limitations and issues . 在前端压缩文件的情况下(例如使用jszip ),客户端可能会更快地下载图像,因为大多数现代浏览器可以同时下载6次,但另一方面,它有自己的局限性和问题

So I would suggest using server-side compression because it's more stable and flexible(using node-zip for example). 所以我建议使用服务器端压缩,因为它更稳定和灵活(例如使用node-zip )。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM