jimmywarting / StreamSaver.js

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

How can i transfer my res.data to Uint8Array #263

Closed broairport closed 2 years ago

broairport commented 2 years ago

I use axios to get data from my backend . I print it out using console.log() ,it's an object.I can download it by using "new blob([res.data])" But when i try to use StreamSaver to download it.i just don't know how can i convert my res.data into Uint8Array. I've tried to use "new Uint8Array(res.data)" to get Uint8Array but it's empty . By the way i set responseType as "blob"

jimmywarting commented 2 years ago

I would recommend against using axios...

why?

only fetch supports streaming...

fetch(url).then(res => {
  res.body.pipeTo(destination)
})