-
-
Notifications
You must be signed in to change notification settings - Fork 4.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This solution still isn't technically correct because it could take more than 40 seconds to download a file. I could simply not revoke any files, but then users would run into issues once they have saved a cumulative total of over 500MB ( https://bugs.chromium.org/p/chromium/issues/detail?id=375297 ) Complain to @sicking and @arunranga for creating and standardizing an incomplete revocation API.
- Loading branch information
Showing
2 changed files
with
20 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
62d219a
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's also hard to fix problems in the spec if no one lets us know about the problem. Looking at the patch I wasn't able to figure out what problem you are referring to.
Please file an issue on the spec if there's a problem with Blob.close()
62d219a
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@sicking
Blob.close()
works fine, but how am I supposed to know when it's safe to call it? My library saves Blobs, and I need to revoke object URLs and Blobs to make room for more (500MB limit in Chrome, similar or higher limits in other browsers) in case the user saves multiple files. There's no event for me to listen to, so I'm just arbitrarily waiting for 40 seconds.62d219a
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How do you save the blob? Generally one a read has started it should be safe to call Blob.close(), it should not affect read operations, like that of
FileReader
or<a href="blob:..." download>
, that are already in progress.If it does then please file a bug on the browser.
62d219a
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For browsers that support
a[download]
, here is what I do, simplified:Not a single browser implements saving blobs like this (not Chrome, not Firefox, not the old Opera, not the new Chromium-based Opera, n/a in Edge & IE as they implement
saveAs
natively (asnavigator.msSaveBlob
), and n/a in Safari as Safari doesn't supporta[download]
). If you revoke the object URL and close the Blob immediately after starting a 50MB download, you can be sure that the download will fail with an error.62d219a
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do make sure that the download is actually started before revoking the URL, or calling .close(). In both Firefox and Chrome, if I revoke the URL after the download has actually started the download finishes just fine.
Firefox pops up a save-as dialog which the user has to interact with before the download starts. I wouldn't be surprised if there's a small delay between when .click() is called and chrome actually starts the download too.
I agree that this is a problem since there's no notification about when the download starts. But there wouldn't be much we could do in the Blob API to indicate when it's safe to revoke a URL or to call .close() if these other APIs haven't even started to read from the blob.
The fix here would either be to introduce a save-as API which takes an actual Blob object, or to fire some form of event from the when the download actually has started (i.e. after any needed user approval).
62d219a
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@sicking Would you mind raising this on a relevant W3C mailing list when you get the time?
62d219a
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I filed a bug to have an event when the download starts or finishes. If you're still able to cancel the download by revoking the URL in chrome, then please file a bug there. I wasn't able to reproduce so I didn't file.
62d219a
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks. Can I get a link to the event bug?
62d219a
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.