jimmywarting / StreamSaver.js

StreamSaver writes stream to the filesystem directly asynchronous
https://jimmywarting.github.io/StreamSaver.js/example.html
MIT License
3.95k stars 413 forks source link

Handle cancel on the browser #309

Closed Tzvetelin88 closed 1 year ago

Tzvetelin88 commented 1 year ago

Is there a way to handle cancelation on the browser?

We start downloading a file, but at some point we click cancel on the browser and we get this:

image

where

writer.write...
writer.close

are not handled properly on my end:

image
Tzvetelin88 commented 1 year ago

Actually I thing I just need to do:

writer.write(new Uint8Array(data.bufferData)).catch(() => {
         .....
          writer.abort;
        });

and to emit signal to the backend to do abort() on the readableStream

jimmywarting commented 1 year ago

If you do have control over the server then i do recommend to use server tech to save a file rather then relying on StreamSaver.js which is intended for huge data generated on the client side, such as a camera recording.

all streamsaver really dose is emulating how a server traditionally saves a file using a service worker to emulate what browser/server have traditionally done for years

Tzvetelin88 commented 1 year ago

Yes, I'm actually doing that on the server side. Using NodeJS fs to R/w files. I'm using StreamSaver.js on the client side, as downloading files is causing browser to crash. I did this implementation - https://github.com/Tzvetelin88/very-big-file-upload-download

StreamSaver works very well on the client side, which I was missing from long time and how to control big file download.