node-formidable / formidable

The most used, flexible, fast and streaming parser for multipart form data. Supports uploading to serverless environments, AWS S3, Azure, GCP or the filesystem. Used in production.
MIT License
7k stars 680 forks source link

Can't parse request with big file #816

Closed majorb22 closed 2 years ago

majorb22 commented 2 years ago

Support plan

Context

What are you trying to achieve or the steps to reproduce?

When I try to upload files from postman, the query can't be parsed, if I upload big files in it. I use the same function, don't change it, but if I attach a big file the parse callback function doesn't run, it logs nothing. The file is created in the uploads map, but nothing else happens.

import formidable from 'formidable';

export const config = {
    api: {
        bodyParser: false,
    },
};

export default function handler(req, res) {
    const options = {
        uploadDir: './uploads',
        keepExtensions: true
    }

    const form = formidable(options);

    form.parse(req, (err, fields, files) => {
        console.log('fields:', fields);
        console.log('files:', files);
    });

    res.status(200).json({ name: 'John Doe' })
}

What was the result you got?

Nothing was logged.

What result did you expect?

To log the files

GrosSacASac commented 2 years ago

res.status(200).json({ name: 'John Doe' }) should be inside the form.parse callback

GrosSacASac commented 2 years ago

Also you should have at least an if statement to see if there is an error in the form.parse callback see the examples https://github.com/node-formidable/formidable/blob/master/examples/with-express.js#L21

majorb22 commented 2 years ago

Thank you!