StreamSaver.js
StreamSaver.js copied to clipboard
How to let StreamSaver "fail" the download?
I'm download files with fetch
and saving them to a zip file. If a network error occurs while fetching, how can I tell browser the download failed rather than just abort
ing it? abort
ing makes browser turn the download item to finished.
Aborting should cancel the download and delete the data that have been written. closing it will end the download normally?
if you pipe stuff that fails then you could try stuff like preventAbort: true
pipeTo(dest, { preventClose, preventAbort, preventCancel, signal } = {})
Think i'm going to need a code example to understand what you are doing.
https://github.com/jimmywarting/StreamSaver.js/blob/master/examples/saving-multiple-files.html#L77
If here a network error occurs in the fetch
, what should I do to tell browser to show the download as "error"?
maybe this will help:
readableZipStream.pipeTo(fileStream)
.catch(err => {
console.log('failed to save the zip...')
})
or while getting the stream
try {
const res = await fetch(url)
if (res.ok) { // status 2xx
res.body
} else {
// the response returned none 2xx response
// continue with the next url or cancel the hole stream
}
} catch (err) {
// network error
}
That will just make my app know there's an error. The browser will show the download as successfully finished.
@Menci fileStream.abort();
will do the trick
@gwdp, it took me a while to realize also that abort
wasn't what menci wanted.
When calling abort it looks like it was... well, aborted by someone. he wants to show it like if it was a network failure (like the picture shown above) I don't believe i'm handling ReadableStreamError as well as i could.