How to zip multiple files and download javascript






















We can then write it to file or combine those blob data into a zip file. This function returns a promise to be resolved as a blob. We can combine with a Promise. But what happens if we need to download a huge amount of files at once? Using Promise. Your code will send a thousand requests at once. There are many problems with that approach:. The solution I thought about is to divide the files into multiple groups. Instead of starting to download them all at once by Promise.

After finishing those 5, I will start another pack. To implement this, we can do a custom logic. Or a simpler way I could suggest is to utilize third-party library bluebirdjs. The library implemented many helpful promise functions. For this use case, I will use Promise.

Notice that Promise here now is the custom Promise provided by the library, not the built-in Promise. Viewed 30k times. When downloaded, zip all the files into one archive with a JavaScript library eg. Prompt the user to save the zip with SaveAs dialog. I'm stuck at passage 2 , how can I zip the downloaded files? Improve this question. Simon Adcock 3, 3 3 gold badges 23 23 silver badges 41 41 bronze badges.

As I read the question, you want to zip all images and provide one zip as a download, right? If you want an example, feel free to look in the source code of my Chrome extension source viewer extension. I see that you've attempted to copy the code from my extension without understanding it, is that correct?

If so, read the documentation for zip. In my extension, I'm downloading a zip-compatible file, and immediately presenting it as a download. That's not OK in your case, because you're downloading a image, and want to zip it. I've just found another question which seems exactly in line with your original and new question: stackoverflow. I know, I already read that answer, but in that case, if the files are downloaded internally by the zip library and not with xhr request in my code , how can I obtain informations on download progress to notify the user in case the files take some minutes to be downloaded?

Show 1 more comment. Active Oldest Votes. Improve this answer. What would be used if we have to deal with a large file? Add a comment. But i can see the last file content is adding to the zip three times. I tried the above script but i'm getting the same file content for both files, i mean when i tried to zip the two files from server, it is zipping two files but i'm getting the same content in both the files.

Below is my code. Doesn't work with firefox File is downloaded, but it's file type is 'File'. But what about downloading files of size 5 GB , 10 GB etc. When I tried this examples, it actually reads all fiiles and writes to a zip. I am looking for a solution where a user should see a zip download happening immediately after download request. I don't have actual files, but have text data on database and want to download the text data as files.

Can I modify this method, somehow? Below is code in which i am creating data for csv file and downloading csv file in zip folder:. Above code working fine and able to download csv file inside zip folder when we got response data for one of junior or Senior student.

I am using the version3 code to download a bunch of pdf from a database. I am using some big paths and those paths are creating the whole folder heirarchy on the zip. Is there a way to just put them on the top of the zip and not creating useless folders?

The mistake I did is zip.



0コメント

  • 1000 / 1000