proposals icon indicating copy to clipboard operation
proposals copied to clipboard

Download API

Open Zipdox2 opened this issue 2 years ago • 0 comments

Introduction

Currently there is no API for downloading files. Specifically, for downloading client-side generated files.

Downloading files is usually accomplished by creating an anchor element, setting its href attribute to the result of calling URL.createObjectURL() with a blob, and setting the download attribute to the filename. This has several limitations though:

  • You can't tell when the download has finished (or if it was started at all)
  • The object URL is a lingering reference to the resource (possibly leaking the memory forever)
  • You can't download streams, only fixed-size data
  • The data must fit in memory

There are two possible workarounds, but they each have their problems.

For downloading streams, you can use a trick with service workers, but service workers are not available in incognito mode, require an additional server resource, and require a secure context.

The alternate solution is to use the File System Access API's showSaveFilePicker(), however, this API is not implemented in Firefox, as Mozilla considers it harmful, and isn't available in any mobile browser. It's also only available in secure contexts.

Use Cases (Recommended)

  • Downloading client-generated files
  • Downloading streamed data
  • Downloading data that is too big to hold in memory

Goals (Optional)

  • Download files though an API without the DOM
  • Download streams
  • Provide the status of the download
  • Progress and error events
  • Option to prompt the user first, user agent may force this
  • Option to prompt the user for the file name and download location

Non-goals (Optional)

  • Provide information about available storage space
  • Provide information about the client's filesystem
  • Providing the download path

Proposed Solution

Without being too prescriptive, articulate a specific way (procedurally, algorithmically, declaratively) that a new or current web technology solves an existing problem or challenge.

Examples (Recommended)

  • File sharing site that progressively decrypts and downloads the files client-side
  • P2P file sharing site (with WebRTC) that transfers files progressively so that they don't need to fit in memory
  • Videoconferencing service that allows recording directly to local storage

Alternate Approaches (Optional)

I mentioned alternate approaches in the introduction.

Privacy & Security Considerations

This API is meant to be straightforward and single-purpose, as opposed to the File System Access API. As I mentioned in the goals section, the user agent may force a prompt before every download, which could be accompanied by the usual "ignore further prompts" option as exists with window.prompt and window.alert. It should therefore be easy to shut down invasive popups. The only information I can think of that this API may reveal is the write speed and/or characteristics of the user's storage device.

Let’s Discuss (Optional)

I've previously discussed a possible download API here: https://github.com/whatwg/html/issues/4148

But I'd like to hear people's opinions on what features the API should have and what the best way to implement such an API would be.

Zipdox2 avatar Jul 23 '23 15:07 Zipdox2