Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fetching files renders invalid blob #145

Open
skourismanolis opened this issue Oct 28, 2020 · 2 comments · May be fixed by #169
Open

fetching files renders invalid blob #145

skourismanolis opened this issue Oct 28, 2020 · 2 comments · May be fixed by #169

Comments

@skourismanolis
Copy link

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.

@kg-currenxie
Copy link

Same :/

@qqilihq
Copy link

qqilihq commented Feb 15, 2021

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.

@fatelei fatelei linked a pull request May 30, 2023 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants