busboy icon indicating copy to clipboard operation
busboy copied to clipboard

emit last file error on unexpected end of multipart data

Open amokrushin opened this issue 8 years ago • 3 comments

Related to: https://github.com/mscdex/busboy/issues/73

amokrushin avatar Nov 21 '16 11:11 amokrushin

I know this is old, but this should be merged as it makes the behavior much more consistent.

A typical use-case I see for this is when you are trying to upload multiple files in a transactional way.

Right now, if the user aborts the query during the upload of the first file, the file emits an error. Otherwise, if the first file gets uploaded completely, all the other won't recieve anything and the upload will just hang/continue without errors (depending on the implementation).

A possible workaround is to rewire all the errors to the files. Something like:

const onerror = (e: any) => file.emit('error', e);
busboy.addListener('error', onerror);
file.once('end', () => this.busboy.removeListener('error', onerror));

Still it doesn't feel like the right approach (it may not cover all the possibilities and generate unexpected results) while a PR as simple as this one can get rid of all the problems at once.

I have tested this code by changing on my machine manually the code and it worked.

marco6 avatar Dec 12 '18 09:12 marco6

If you can provide a minimal reproduction against the current master branch, let me know.

mscdex avatar Dec 19 '21 20:12 mscdex

Hi, I don't know if it applies anymore, given it's 3 years ago (and the PR is 5 years ago!).

I am moving away from NodeJS, but I think you should be able to reproduce by sending 2 files in a multipart request and removing the last byte from the second file. This should be doable easily in node.

marco6 avatar Dec 20 '21 10:12 marco6