I am unable to create a blob from the response stream of a request (the response comes from a node js server), here is the code:
fetch('/api/load', {
method: 'POST',
headers: { 'Content-Type': 'text/plain' },
body: src
}).then((response) => {
const reader = response.body.getReader()
return new ReadableStream({
start(controller) {
return pump()
function pump() {
return reader.read().then(({ done, value }) => {
if (done) {
controller.close();
return;
}
controller.enqueue(value);
return pump();
})
}
}
})
}).then((stream) => {
// What to do next with the stream???
})
I already tried new Blob([new Uint8Array(stream)], {type: 'image/jpeg'}), but it doesn't work :(
What is the correct way to create a blob from the stream?