Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

parse() callback never call with some files #923

Closed
nikis opened this issue Feb 9, 2023 · 3 comments
Closed

parse() callback never call with some files #923

nikis opened this issue Feb 9, 2023 · 3 comments
Labels

Comments

@nikis
Copy link

nikis commented Feb 9, 2023

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 nikis added the bug label Feb 9, 2023
@tunnckoCore
Copy link
Member

@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.

@nikis
Copy link
Author

nikis commented Feb 13, 2023

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

@nikis
Copy link
Author

nikis commented Feb 13, 2023

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.

@nikis nikis closed this as completed Feb 13, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants