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

Handle empty filenames as fields instead of files #258

Closed
cyantree opened this issue Nov 14, 2021 · 2 comments
Closed

Handle empty filenames as fields instead of files #258

cyantree opened this issue Nov 14, 2021 · 2 comments

Comments

@cyantree
Copy link

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.

@mscdex
Copy link
Owner

mscdex commented Dec 19, 2021

If it's any consolation, you can also use application/octet-stream as the mime type to force it as a file.

@cyantree
Copy link
Author

Thanks for the response. Unfortunately that doesn't work with the given feature from fastify-multipart as this requires the content type to be application/json.

However Fastify forked this repo and added a config option that gives the developer the possibility to decide which part is a field or a value.
https://www.npmjs.com/package/@fastify/busboy - See isPartAFile

I will close this issue as it has been fixed in the fork.

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

2 participants