-
Notifications
You must be signed in to change notification settings - Fork 2.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Event to indicate download started and/or finished #954
Comments
Actually, per the specifications, cloning of the blob should happen once you assign the URL in |
I thought that cloning happened once loading starts? Is that different for |
Cloning happens during parsing: https://url.spec.whatwg.org/#concept-url-parser. And parsing happens directly. That's the only deterministic model we could come up with. |
Ok. If this is something browser vendors has agreed is implementable then we can close this request (unless we want to keep it open to satisfy the "remove UI when download starts" use case). Though so far it doesn't seem like browsers have implemented? |
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.
Yeah, I don't think browsers have implemented the deterministic model. I hope they will since determinism is better, doh, but if they don't we need a redesign, which will be sad. Irrespective of blobs it might still make sense to have start/finish events for downloading, to display "waiting UI". I don't know how much privacy concerns we have with that, potentially it's not great for cross-origin resources? |
Although I agree that ideally download start/finish events should be same-origin (and CORS)-only, timing information for cross-origin resource loading is already exposed via |
How about some progress event also? Little of track here but: I had one idea to be able to skip creating/revoking url all together using // <a href="intercept-me" download="sample.zip">download sample.zip</a>
// service worker
self.addEventListener("fetch", evt => {
if( evt.request.url.indexOf('intercept-me') ){
let stream = new ReadableByteStream()
let res = new Response(stream, {
headers: {
// Specify a filename
'Content-Disposition': 'attachment; filename=sample.zip',
}
})
// Replace download link with a readable stream
evt.respondWith(res)
// do something with stream (generate a 2GB large zip file)
}
}) This way you could create a async saving stream and be able to save much larger file Now ReadableByteStream isn't available yet so it wouldn't work. So i tried emulating 206 partial download but was unsuccessful. This would require a service worker to intercept a[download] link that means it has to be in https (SSL) Tried creating a objectUrl from a audio stream first to use with a[download] but it didn't work. |
Tada: https://github.com/jimmywarting/StreamSaver.js |
Let's merge this into #4148. |
The best way to enable a website to save a Blob or File is by doing something like:
<a id=downloader href="" download>
and
The problem is that there's no good time to revoke the object URL. The problem is that browsers tend to start the download asynchronously after the link has been clicked. This is especially browsers which show the user a "do you want to open or download this file?" dialog, where the download might start long after the link was clicked.
Per the Blob spec, it should be fine to call
URL.revokeObjectURL(url)
as soon as the download has started, but there's no way to know when that is.We should fire an event either when the download actually starts, or when it finishes. This could also be useful to allow the webpage to hide the download link once the user actually starts downloading, rather than when they click the link.
The text was updated successfully, but these errors were encountered: