unfetch icon indicating copy to clipboard operation
unfetch copied to clipboard

fetching files renders invalid blob

Open skourismanolis opened this issue 4 years ago • 2 comments

How it should be

let e = await fetch('https://i.imgur.com/4AiXzf8.jpg')
// Response { type: "cors", url: "https://i.imgur.com/4AiXzf8.jpg", redirected: false, status: 200, ok: true, statusText: "OK", headers: // Headers, body: ReadableStream, bodyUsed: false }
await e.blob()
// Blob { size: 87363, type: "image/jpeg" }

How it is with unfetch

let e = await fetch('https://i.imgur.com/4AiXzf8.jpg')
// Object { ok: true, statusText: "OK", status: 200, url: "https://i.imgur.com/4AiXzf8.jpg", text: text(), json: json(), blob: blob(), clone: a(), headers: {…} }
await e.blob()
// Blob { size: 156997, type: "" }

Note how the blob's size is different and the type is missing.

That can also be confirmed by using FileReader.readAsDataURL() on the generated blob, the resulting file is invalid and cannot be opened.

skourismanolis avatar Oct 28 '20 10:10 skourismanolis

Same :/

kg-currenxie avatar Dec 09 '20 13:12 kg-currenxie

Any workarounds or attempts to fix this?

The issue is obviously here:

https://github.com/developit/unfetch/blob/master/src/index.mjs#L16

To fix this, the XHR would probably need to be initialized with the proper responseType, which at first glance will require some deeper refactoring of the current structure.

qqilihq avatar Feb 15 '21 11:02 qqilihq