You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The text was updated successfully, but these errors were encountered:
aamironline
changed the title
Does it support zipping multiple S3 objects without downloading locally?
Does it support zipping multiple S3 objects and sending to Django response stream without downloading locally?
Nov 2, 2020
I'm afraid that functionality would be outside of the scope of this package. However, zipstream does support streaming input files. So if you have an S3 library that can stream the data instead of storing it locally, you can probably use those streams as inputs for zipstream and then stream the zipped output to the browser. In that case, the data would never touch your server's disk.
The approach below worked for me. It relies on using requests with signed URLs from S3, but I imagine the same can be achieved with S3.Client.download_fileobj in boto3.
some_list_of_files_to_get_from_s3= [
(<s3signedurl>, '<name of file>'),
...
]
z=zipstream.ZipFile(mode="w", compression=zipstream.ZIP_DEFLATED)
foreach_s3_signed_url, file_nameinsome_list_of_files_to_get_from_s3:
withrequests.get(each_s3_signed_url, stream=True) asr:
z.writestr(file_name, r.content) # this worked for me# tried the following but could not get it to write data to the files in the zip archive:# z.write_iter(file_name, r.iter_content())
With Django, it was then matter of passing z into StreamingHttpResponse to round out the view code:
@gassc Thank you for your comment, I'm just solving a similar problem.
Do you know if your approach can work the same way with Django-storages, I know it's using boto under the hood but not much else.
If yes, can you provide an example? Any issues?
The text was updated successfully, but these errors were encountered: