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.

"Finish" and "field" events does not work when "file" event is added.

See original GitHub issue

For eg:

This works!

const registerBusboyFields = (req, res, next) => {
  req.uploadBody = {};

  req.busboy.on("field", function (name, value) {
    req.uploadBody[name] = value;
    console.log(name, value);
  });

  // Finished all busboy events
  req.busboy.on("finish", () => {
    // The finish event is triggered...
    console.log(req.uploadBody);
    next();
  });

  req.pipe(req.busboy);
};

This does not work 😦

const registerBusboyFields = (req, res, next) => {
  req.uploadBody = {};
  req.busboy.on("file", function (name, file, info) {
    req.uploadBody[name] = info;
    console.log(info);
  });

  req.busboy.on("field", function (name, value) {
    req.uploadBody[name] = value;
    console.log(name, value);
  });

  // Finished all busboy events
  req.busboy.on("finish", () => {
    // The finish event is NOT triggered...
    console.log(req.uploadBody);
    next();
  });

  req.pipe(req.busboy);
};

PS: When i say “does not work”, i mean, i just see the console.log happening on “file” event, but console.log does neither happen on “field” event not in “finish” event.

Am I doing something wrong?

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
mscdexcommented, Feb 23, 2022

Assuming the filename is coming from the file part, then no. If the filename is being transmitted separately from the file part, as a normal field ('field' event), then obviously yes.

Also FWIW, in general filenames given by a user/client in forms should rarely be used as-is as they could contain a malicious value.

2reactions
mscdexcommented, Feb 22, 2022

file is a readable stream. You have to read all of its contents whether you care about them or not in order for the form parsing to complete.

Read more comments on GitHub >

github_iconTop Results From Across the Web

busboy not firing finish event - Stack Overflow
So, what i see that both the fields and the files are being logged in console but the finish event is not getting...
Read more >
busboy, upload few files, 'finish' event doesn't work properly
I trying to upload few files through one input[type=file] with attribue 'multiple'. All work fine but 'finish' event firing before realy all ...
Read more >
Known Issues - The Events Calendar
To do this, open the event and change the start date or start time, and hit Update. Then change the date or time...
Read more >
Event File Not Found After Importing
Event File Not Found After Importing · Click File · Click Import · Click Meet Events · Double-click the event file · Click...
Read more >
Handling Events :: Eloquent JavaScript
This works for most types of events—you can attach a handler through the attribute whose name is the event name with on in...
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