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

Blob type set to empty string causing InvalidStateError #25971

Closed
db213 opened this issue Oct 1, 2024 · 4 comments
Closed

Blob type set to empty string causing InvalidStateError #25971

db213 opened this issue Oct 1, 2024 · 4 comments

Comments

@db213
Copy link

db213 commented Oct 1, 2024

Version:
deno 2.0.0-rc.9 (release candidate, release, aarch64-apple-darwin)
v8 12.9.202.13-rusty
typescript 5.6.2

Hi there,

I'm trying to use the fetch API to grab a locally saved file. I'm using loadImageBitmap with an absolute path to a JPG file passed in as the url, prefixed with file:///. I can see that the the fetch has succeeded, however the resulting blob from const blob = await res.blob() looks like Blob { size: 695303, type: "" } and the empty string value of type is causing the following error:

error: InvalidStateError: Unsupported type ''
    at ext:deno_canvas/01_image.js:236:15
    at eventLoopTick (ext:core/01_core.js:175:7)
    at async loadImageBitmap (file:///Users/daphnebogosian/Library/Caches/deno/npm/registry.npmjs.org/webgpu-utils/1.9.2/dist/1.x/webgpu-utils.module.js:5937:12)
    at async Promise.all (index 2)
    at async createTextureFromImages (file:///Users/daphnebogosian/Library/Caches/deno/npm/registry.npmjs.org/webgpu-utils/1.9.2/dist/1.x/webgpu-utils.module.js:5963:24)
    at async ResourceSetUnkeyed.<anonymous> (file:///Users/daphnebogosian/Documents/d2p-mk2/packages/engine/src/lib/resources/image-textures-async/index.ts:22:21)

I'm stumped on how to get around this, any tips or suggestions on what I'm doing wrong much appreciated , but also it looks like to me that the type is probably erroneously being set to '' based on the documentation for ResponseType.

Edit: I've realised I was looking at the documentation for Response and not for Blob. Blob::type is typed as just a string so it can very validly be set to empty string.

Edit2: Looks like when fetch resolves to reading a blob out of the filesystem, the content-type of the response is not set. And then the mimetype becomes null/''.

Thanks so much for reading!

@littledivy littledivy added the bug Something isn't working correctly label Oct 2, 2024
@Hajime-san
Copy link
Contributor

Hajime-san commented Oct 2, 2024

I think you should use your own file server that respond content-type header instead fetch('file:///...').

@db213
Copy link
Author

db213 commented Oct 2, 2024

Thank you, that helped me get a little further! The type is now set correctly to image/jpeg, however it looks like jpegs simply aren't supported at the moment? (Though for now I should be able to get away with converting to pngs)

Additionally, when I try to use PNGs instead of JPEGs I run into the following problem so my PNGs need to fulfil certain requirements as well?

error: TypeError: Color type 'Rgb8' not supported
    at ext:deno_canvas/01_image.js:241:50
    at eventLoopTick (ext:core/01_core.js:175:7)
    at async loadImageBitmap (file:///Users/daphnebogosian/Library/Caches/deno/npm/registry.npmjs.org/webgpu-utils/1.9.2/dist/1.x/webgpu-utils.module.js:5936:12)

@Hajime-san
Copy link
Contributor

The enhancement of createImageBitmap API is going here.
If this PR will shipped, basic jpeg will be available.

@lucacasonato lucacasonato removed the bug Something isn't working correctly label Oct 3, 2024
@lucacasonato
Copy link
Member

We do not set content-type for local file fetches. This is documented here, and is expected behaviour: https://docs.deno.com/runtime/reference/web_platform_apis/#fetching-local-files

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

No branches or pull requests

4 participants