Re: [request] "Download" Event for HTMLAnchorElement

If a developer creates an object URL, e.g. theFile =
URL.createObjectURL(theData), then it's the developer's responsibility to
revoke that object URL. Assigning theFile to an anchor href so the data can
be downloaded doesn't create a copy of data.

The web browser will definitely know when the data has been written to
disk, the problem is the developer won't know when the data has been
written to disk, so it's currently impossible to revoke the object URL
(release the data from memory) at a safe time. When the anchor is clicked
you could create a timer and revoke the object URL after a certain number
of seconds have elapsed but you will still be taking a shot in dark.

Ideally we need to be able to do something like this ...

anchor.ondownload = function(e) {
  URL.revokeObjectURL(theFile);
}

A simplified example of course, but it demonstrates what's needed.

// Si




On 24 March 2014 18:51, Brian Matthews (brmatthe) <brmatthe@cisco.com>wrote:

> On 3/23/14 5:30 PM, "Si Robertson" <retromodular@gmail.com> wrote:
>
>
> >Hi guys,
> >
> >This mailing list was suggested to me by one of the Chromium developers,
> >so I apologize in advance if this mailing list is not appropriate for
> >this request/proposal.
> >
> >In a nutshell, I am asking for a "download" event to be dispatched from
> >anchor elements that support the "download" attribute.
> >
> ><a href="blob:..." type="..." download="..."
> >ondownload="release(this)">download</a>
> >
> >The problem that this new event would solve is this - when using a
> >temporary object URL (blob) for the file data, e.g. programmatically
> >generated content, there is currently no way of knowing when that file
> >data has been written to disk, therefore there
> > is no reliable way of knowing when it is safe to revoke the object URL
> >in order to release resources.
> >
> >Thanks for your time.
> >
> >Regards,
> >Si Robertson
>
>
> Is the download generating a temporary copy of the blob to do the
> download? If so, it seems it should be up to the browser to handle
> cleaning it up, not the developer. If referring to the blob referenced by
> the href, won't releasing it after the first download prevent it from
> being downloaded again? Maybe an edge case, but not one I would want to
> preclude. Also, if the browser doesn't know when the file's been
> downloaded, how does it know when to fire the ondownload event?
>
> Probably newby questions, but I'm working on some code that does exactly
> this, programmatically generates anchors referencing programmatically
> generated blobs, so I want to understand how they're handled and what
> requirements are put on me to make sure things are cleaned up as
> necessary.
>
> Thanks,
> Brian
>
>

Received on Monday, 24 March 2014 19:46:23 UTC