Wait for user to finish downloading a blob in Javascript

♀尐吖头ヾ 提交于 2019-12-11 02:34:53

问题


In Javascript, I'm creating a number of blobs that I want to prompt the user to save as files. At the moment, I'm doing that using URL.createObjectURL, placing the URL in a link, and simulating a click to the link. (Of course I call URL.revokeObjectURL to release the URL so the blob can be discarded after the user saves it.) I have a loop that runs through and does this for each blob I want the user to save.

At least on Firefox, triggering the link is an asynchronous operation; I call click() and my loop to generate the rest of the blobs immediately continues execution before the user chooses a location to save the file.

This presents a bit of a problem because each blob could be somewhat large, and there could be a lot of them. I can easily foresee a situation where there wouldn't be sufficient memory to hold all of them in memory waiting for the user to save and release them one-by-one. So I'd like to generate one blob, have the user download it, and then, after the file has been saved (and thus is eligible to be discarded by the garbage collector), proceed to generate the next blob and have the user save it.

Is there any way to achieve this without requiring the user to manually click another button or some such thing to signal the page that he is done saving the file?

来源:https://stackoverflow.com/questions/29200256/wait-for-user-to-finish-downloading-a-blob-in-javascript

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!