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

File to Blob #3119

Closed
yusukebe opened this issue Jul 10, 2024 · 7 comments · Fixed by #3120
Closed

File to Blob #3119

yusukebe opened this issue Jul 10, 2024 · 7 comments · Fixed by #3120
Labels
enhancement New feature or request.

Comments

@yusukebe
Copy link
Member

What is the feature you are proposing?

This is not a bug or a new big feature but a minor change that will be fix.

As @nakasyou said in this comment, FormData can accept Blob object as a value. It's better than File, that subclass of Blob. We have to replace File to Blob.

@EdamAme-x
Copy link
Contributor

hmm..

As @nakasyou said, File extends Blob

playground

But, Node.js is using string | File.
So I think current types is better.

https://github.com/nodejs/node/blob/b4e8f1b6bb3616ba222c4513218aa1fa9d543d8e/deps/undici/src/types/formdata.d.ts#L10

@EdamAme-x
Copy link
Contributor

According to this jsdoc, if a Blob object is passed to formData, it will be a File object named blob.

@param value The field's value. This can be [`Blob`](https://developer.mozilla.org/en-US/docs/Web/API/Blob)
    or [`File`](https://developer.mozilla.org/en-US/docs/Web/API/File). If none of these are specified the value is converted to a string.
@param fileName The filename reported to the server, when a Blob or File is passed as the second parameter. The default filename for Blob objects is "blob". The default filename for File objects is the file's filename.

@nakasyou
Copy link
Contributor

nakasyou commented Jul 10, 2024

@EdamAme-x, it's a used in output only.
In your URL, get receives unknown, and it says that get can receive Blob.1

FormValue in Hono is for input, so we should change it.

Footnotes

  1. https://github.com/nodejs/node/blob/b4e8f1b6bb3616ba222c4513218aa1fa9d543d8e/deps/undici/src/types/formdata.d.ts#L39

@EdamAme-x
Copy link
Contributor

EdamAme-x commented Jul 10, 2024

Thanks for reply @nakasyou

FormValue in Hono is for input

Can you elaborate on this part?

After parsing, I think it appears to be treated as just a Record object. 1
I think this type is Record<string, string | File | string[] | File[]>.

Footnotes

  1. https://github.com/honojs/hono/blob/ec58511247d7b9c33fff92ea992c127c6363eec0/src/validator/validator.ts#L114

@nakasyou
Copy link
Contributor

@EdamAme-x

Can you elaborate on this part?

Client uses ValidationTargets as input.
BodyData can receive Blob, so client should receive Blob

@EdamAme-x
Copy link
Contributor

Thanks @nakasyou
I think this requires a change of type between Client and Server.
I'll create PullRequest about this.

@fzn0x
Copy link
Contributor

fzn0x commented Jul 10, 2024

I've been using Hono with Bun in production apps, and I'm using just Blob to upload files! so I think it is necessary to do this changes 🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants