🪴 notes

Search

Search IconIcon to open search

getting file out of fetch response

Published Aug 1, 2023 Last updated Aug 3, 2023 Edit Source

For an endpoint that returns a file via fetch, the file can be accessed by:

1
2
const res = await fetch();
const blob = await res.blob();

Then it can be used as src for <img> <iframe> etc using createObjectURL.

1
2
3
const fileLink = URL.createObjectURL(blob);

// <img src={fileLink}/>

Reading content from a Blob can also be done.