Vanilla NodeJS `request.on('end') is being called before `formidable.parse` completes
See original GitHub issueSupport plan
- which support plan is this issue covered by? Community:
- is this issue currently blocking your project? yes
- is this issue affecting a production system? no
Context
- node version: 15.2.1
- module (formidable) version: 1.2.2
- environment (e.g. node, browser, native, OS): node, Windows 10
- used with (i.e. popular names of modules): Vanilla NodeJS
- any other relevant information:
What are you trying to achieve or the steps to reproduce?
Trying to upload a simple file around 100 KB. There is a branch in the code below for handling multi-part form data. We want formidable
to handle that. We want to handle all other requests via the second branch.
import * as formidable from 'formidable';
// Handle incoming HTTP requests
httpServer.on('request', (request, response) => {
let body;
if (request.headers['content-type'].includes('multipart/form-data')) {
formidable.parse(request, (error, fields, files) => {
// Process multi-part form data
body = files;
});
}
else {
request.on('data', data => {
// Process other
body = data;
});
}
// Handle completion of the read operation above
request.on('end', async () => {
// Do something with body
response.write(body);
});
});
What was the result you got?
This works some of the time. But there is a race condition because the last bit request.on('end')
is being called before formidable.parse
completes.
What result did you expect?
One that works — I know that’s controversial.
Issue Analytics
- State:
- Created 3 years ago
- Comments:6 (3 by maintainers)
Top Results From Across the Web
chore(deps): bump ini from 1.3.5 to 1.3.7 (#665) · node-formidable ...
Vanilla NodeJS `request.on('end') is being called before `formidable.parse` completes Vanilla NodeJS `request.on('end') is being called before `formidable.parse ...
Read more >How to avoid early return on formidable functions in Node js
It works as expected except the early return from the method. There the method returned before fire 'fileBegin' and 'file' events. Could you ......
Read more >Differences between formidable callbacks, events ... - Medium
As formidable is parsing the request, when the callback is provided, formidable will collect all fields and files and pass to the callback....
Read more >Node.js Notes for Professionals
Section 3.11: Hook: How to execute code before any req and after any res ... response.end(http. ... When called without arguments, Node.js starts...
Read more >How to use IncomingForm function in formidable - Tabnine
formParse: function (callback) { var form = new formidable. ... IncomingForm(); form.parse(request, (error, fields, files) => { var oldPath = files.
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
@NoelAbrahams yep, something like #635 looks beautiful and modern.
@tunnckoCore I’m going to close this issue, as it was really more of a question, and there doesn’t seem to be anything to fix.