parse() callback never call with some files
nikis opened this issue · comments
Support plan
- Which support plan is this issue covered by: Community
- Currently blocking your project/work?: no
- Affecting a production system?: yes
Context
- Node.js version: 18.13.0
- Release Line of Formidable: Current
- Formidable exact version: 2.1.1
- Environment: node
- Used with: -
What are you trying to achieve or the steps to reproduce?
import http from 'node:http';
import formidable from 'formidable';
const server = http.createServer((req, res) => {
if (req.url === '/api/test' && req.method.toLowerCase() === 'post') {
// parse a file upload
const form = formidable({});
form.parse(req, (err, fields, files) => {
if (err) {
res.writeHead(err.httpCode || 400, { 'Content-Type': 'text/plain' });
res.end(String(err));
return;
}
res.writeHead(200, { 'Content-Type': 'application/json' });
res.end(JSON.stringify({ fields, files }, null, 2));
});
return;
}
res.writeHead(200, { 'Content-Type': 'text/html' });
res.end(``);
});
server.listen(3000, () => {
console.log('Server listening on http://localhost:3000/ ...');
});
What was the result you got?
parse() callback never called with some random files
curl localhost:3000/api/test -F test='mest' -F video=@/test.mp4
If i call without file, callback is fired and fields its filled
curl localhost:3000/api/test -F test='mest'
What result did you expect?
parse() callback to be fired always
@nikis hi, very strange. It's very basic stuff and it's from the readme which is working. Maybe the problem is in the file, or it's too big or something like that.
The file I'm trying with is not big - about 500kb. It also happens with other non-video files. Everything is very random which also makes debugging difficult.
Also i add some listeners fileBegin
event is triggered
form.once('error', console.error);
form.on('fileBegin', (formname, file) => {
console.log('fileBegin', formname, file);
});
form.on('file', (formname, file) => {
console.log('file', formname, file);
});
form.on('field', (fieldName, fieldValue) => {
console.log('field', fieldName, fieldValue)
});
form.once('end', () => {
console.log('Done!');
});
Also if i set uploadDir option , actually the file is created in this directory
The problem occurs only when i use devcontainer (local machine, not in GitHub Codespaces etc). If i run outside, everything it's working as expected.