简体   繁体   English

Django多张照片下载

[英]Django multiple photo download

I developed a photo gallery in python, now I want to insert a new feature, "Download Multiple Photos": a user can select some photos to download and system creates a compressed file with the photos. 我用python开发了一个图片库,现在我想插入一个新功能“下载多张照片”:用户可以选择一些照片进行下载,然后系统会使用这些照片创建一个压缩文件。

In your opinion: in the frontend what is the best way to send the ids? 您认为:在前端,发送ID的最佳方法是什么? Json? 杰森 input hidden? 输入隐藏? and in the backend there is a django library that compress the selected photos and return the compressed file? 在后端有一个django库,可以压缩所选照片并返回压缩文件?

Thanks, Marco 谢谢,Marco

Once you get the IDs of all the selected image in the client, you can zip them by using the zipfile or tarfile module . 一旦在客户端中获得所有选定图像的ID,就可以使用zipfiletarfile模块对它们进行压缩。 The way to collect the files to compress totally depends on how did you save the image. 收集文件进行压缩的方式完全取决于您如何保存图像。 If you save the image such as uploaded date/id/, then on the client side, you need to send those information back to the server as well to reduce the server load. 如果保存图像,例如上载的日期/ id /,则在客户端,还需要将这些信息发送回服务器,以减轻服务器负载。 Hidden fields are ok in this situation 在这种情况下,隐藏字段是可以的

I think the only way to do it is in the backend, because in the frontend you will only have to select which photos you want to download and send the ids or some identifiers to the server side, then retrieve those selected photos from the filesystem (based on the identifiers), compress them in a single file and return that compressed file in a response as attached content. 我认为唯一的方法是在后端,因为在前端,您只需选择要下载的照片并将ID或某些标识符发送到服务器端,然后从文件系统中检索那些选择的照片(根据标识符),将其压缩为单个文件,然后在响应中将该压缩文件作为附件返回。

If you do it in the front end how would you get each file and compress them all? 如果在前端执行此操作,将如何获取每个文件并将其全部压缩?

Doing it in server side is the best solution in my opinion :) 在我看来,在服务器端做到这一点是最好的解决方案:)

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

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