question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Empty formdata body stalls the parser

See original GitHub issue

No full example yet, but the basic steps to reproduce would be this from a browser:

var xhr = new XMLHttpRequest();
var fd = new FormData();

fd.append('file', new Blob(), 'file.txt');
xhr.open('POST', '/');
xhr.send(fd);

The file event is raised correctly, but it seems to never emit a finish. I suspect the first empty file to be encountered will stall the whole upload request.

Issue Analytics

  • State:closed
  • Created 8 years ago
  • Comments:6 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
mscdexcommented, Jun 29, 2016

@BlaM An easier way is to just do file.resume() if you want to skip over the current file.

Adding that in this module would not be acceptable however since busboy cannot make any assumptions about what the consumer of this module is doing. Adding a data handler or calling .resume() will cause the stream to flow. If someone needs to perform an async operation before reading from the file, they would lose data. All (“streams2” or newer) streams since node v0.10 start in a paused state. FWIW a similar issue may arise if you only read part of the file stream, since busboy also handles backpressure properly.

1reaction
BlaMcommented, Jun 29, 2016

Okay, I guess I start to understand now. There NEEDS to be someone listening to the file - if that does not happen, it will never reach “end”:

So if you do THIS:

        req.busboy.on('file', function(name, file, filename, encoding, mimetype) {
             if (!filename || filename === '') {
                return;
            }
            // do stuff if there is a filename
            file.pipe(....

This will freeze and stop doing things.

You need to at least have someone listening to “data”:

    file.on('data', function() {});

Adding this line into multipart.js right before the file.on("end") event fixed the problem for me, too. It should be in the code using busboy - but maybe having this blank “fallback data handler” in busboy itself might avoid confusion?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Express body-parser req.body with formdata is empty object
To log every field in formData let myForm = document.getElementById('myForm'); formData = new FormData(myForm); for (let [key, ...
Read more >
Node.js Undici
The body mixins are the most common way to format the request/response body. ... .text() mixin first and then manually parse the text...
Read more >
Uploading an object using multipart upload - Amazon Simple ...
You can use the multipart upload to programmatically upload a single object to Amazon S3. For more information, see the following sections.
Read more >
Karate | Test Automation Made Simple.
Karate will attempt to parse the raw HTTP response body as JSON or XML and make it available as the response value. If...
Read more >
XmlHttpRequest - Http requests in Excel VBA (Updated 2022)
A simple POST request to send form data : ... Read : Parse HTML in Excel VBA – Learn by parsing hacker news...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found