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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle empty filenames as fields instead of files #26

Closed
2 tasks done
kibertoad opened this issue Nov 28, 2021 · 3 comments
Closed
2 tasks done

Handle empty filenames as fields instead of files #26

kibertoad opened this issue Nov 28, 2021 · 3 comments

Comments

@kibertoad
Copy link
Member

kibertoad commented Nov 28, 2021

Prerequisites

  • I have written a descriptive issue title
  • I have searched existing issues to ensure the feature has not already been requested

馃殌 Feature Proposal

When crafting browser requests it doesn't seem possible to leave out the filename in case you want to send a blob:

const body = new FormData();
body.append('json', new Blob(['{"foo":"bar"}'], {type: 'application/json'}));
fetch('/test', {method: 'POST', body});

Uses "glob" as filename.

const body = new FormData();
body.append('json', new Blob(['{"foo":"bar"}'], {type: 'application/json'}), '');
fetch('/test', {method: 'POST', body});

Uses "" as filename.

const body = new FormData();
body.append('json', new Blob(['{"foo":"bar"}'], {type: 'application/json'}), null);
fetch('/test', {method: 'POST', body});

Uses "null" as filename.

Therefore such requests are handled as file because of this undefined check:
https://github.com/mscdex/busboy/blob/master/lib/types/multipart.js#L174

Is it reasonable to also accept parts with empty filenames as fields? Wouldn't a real file always have a filename?

I think that this could be seen as breaking change.

A minor change would be adding an option for a custom filtering handler which let the user decide whether a specific part should be handled as file or field.

@kibertoad
Copy link
Member Author

Originally brought up by @cyantree in fastify/fastify-multipart#292

@cyantree
Copy link

Thanks @kibertoad for preparing the fork and migrating this issue. I'll prepare a pull request for it later.

@cyantree
Copy link

cyantree commented Dec 1, 2021

Will be handled through #53

@Uzlopak Uzlopak closed this as completed Dec 2, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants