I'm currently on the lookout for a solution to download large files (around 2 - 4 GB) from a bearer token protected api endpoint that is compatible with all common browsers including IE 11, Chrome, Firefox, Android Browsers, and Safari. I want it to work seamlessly with angular/ts in browsers only without needing to provide an app.
Challenges with FileSaver
Currently, I am using eligrey/filesaver which consolidates various browser-specific options for client-side blob downloads. This allows me to easily incorporate the bearer token (e.g., with http interceptors).
The issue arises when IE experiences high RAM consumption and freezes at a 1.4GB download.
Issues with StreamSaver
After exploring a more modern approach with StreamSaver.js, I discovered that it only works with chrome and opera, offering direct streaming to disk.
Dilemma with an Unprotected Endpoint
Another common method would involve allowing anonymous access to the download endpoint by requesting a one-time-token first, generating a URL with this token, and prompting the user to download it directly through a new tab opened by the browser and closed immediately upon starting the download.
This technique requires 2 requests for a single download and may not be ideal for mobile browsers due to the need to open a new tab for downloading. It also appears somewhat hacky, at least in my opinion. The API must ensure that URLs are valid for a limited time and/or cannot be used consecutively.
Any Suggestions?
If anyone has suggestions for a clean, modern, state-of-the-art, and efficient way to handle such a typical scenario, I would appreciate your insights.
How do major companies like Google Drive, Dropbox, and Amazon address this issue?
Personally, I lean towards letting the browser handle the file download instead of client-side blob downloads. Is there a way to automatically include bearer tokens as default request headers in the browser when a client clicks on a link (href'ed)?
Why is it challenging for a modern angular-rich client to delegate a secure binary download to the browser effortlessly?