1

I have found several threads where the same question has been asked, but I suspect that the top answer in most of them are outdated.

My problem

I have a frontend javascript app communicating with an oauth authenticated API. This API contains files I want my users to be able to download. Because the API requires authentication, I can not show the user a regular link in order to initiate the download.

Instead, I have to send a XHR-request to initiate the download (so I can add the necessary authentication header).

In my case, the files will usually be pretty large (>1GB), so keeping them in memory is not a solution.

Reading this article, I'm wondering if it might be possible to stream the file from the API to the filesystem through the Javascript file API. Does anyone have a suggestion on how I might make this work?

Isn't this a pretty common problem in 2016?

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
andrroy
  • 128
  • 1
  • 6

1 Answers1

0

It is somewhat hack-ish, but I've used it before and it works wonders.

From Downloading file from ajax result using blob

Community
  • 1
  • 1
Valentin Roudge
  • 555
  • 4
  • 14
  • 1
    Nice! This seems to work. But does it work for big files? In a worst case scenario, a file can probably be around 10 GB. – andrroy Nov 08 '16 at 21:29
  • Well you got to try it and let me know, I'm eager to know :D. I always used it for CSV and XLS before. – Valentin Roudge Nov 08 '16 at 21:29
  • 2
    Trying it out now! – andrroy Nov 08 '16 at 21:30
  • 1
    Unfortunately this doesn't work for me. I tried to download a 8GB file, which in itself works OK. Even though the user does not receive any feedback while the file is loading, I added a loading bar to indicate the status of the download. But after the download was complete, the user also had to copy the content from the blob to a new file in the file system. Since my app is supposed to be a software distribution system, this solution is not good enough to run in production :( – andrroy Nov 09 '16 at 12:39