mscdex / busboy

A streaming parser for HTML form data for node.js
MIT License
2.86k stars 213 forks source link

Prioritize text fields over file fields? #230

Closed yaneony closed 3 years ago

yaneony commented 4 years ago

Right now busboy takes fields as they are, if file field comes as first one and then text field, it will fire "file" event and then "field".

The problem comes if you have some kind of validation/check routines and combine text with file fields together. It will first upload the whole file and then it will fire "fields" event where you can check if some fields are wrong or missing. That will add overhead to whole FS.

Imagine, you will let your customers upload some files over 1-2GB. They will write some title and choose file. You will have to check for some forbidden symbols in title... Your customer will have to wait until file is fully uploaded to get error about wrong title. Bad?

Is it possible internally to sort fields so, that "file" event will be fired always at the end if "fields" are provided?

Thanks!

jaydenseric commented 4 years ago

The server can't control the order that the client sends multipart form fields/files. I'm not sure what your asking for here; busboy is a server package.

The fields can be ordered on the client, which should solve your problem. The GraphQL multipart request spec for example mandates the order of fields the client sends:

https://github.com/jaydenseric/graphql-multipart-request-spec#multipart-form-field-structure

mscdex commented 4 years ago

You would just need to enforce an order on the server side to prevent issues like that. Most clients implicitly support this by appending to the end of the form for example.

markstos commented 3 years ago

This issue can be closed.