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?