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
7.05k stars 682 forks source link

form.parse callback is not called when run on Firebase functions (Node v8) #657

Closed helloforward closed 4 years ago

helloforward commented 4 years ago

Support plan

Context

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

exports.importExcelSpreadsheet = functions.https.onRequest(async (req, res) => {
  try {
    console.log('Parsing multipart form');

    const parsedForm = await new Promise((resolve, reject) => {
      console.log('Start parsing form');

      const form = new formidable.IncomingForm();
      form.parse(req, (err, fields, files) => {
        console.log('Finished parsing form');

        if (err) {
          return reject(err);
        }

        resolve({fields: fields, files: files});
      });
    });

    console.log('parsedForm', parsedForm);

    var file = parsedForm.files.fileToUpload;
    if (!file) {
      throw new Error("No file to upload, please choose a file.");
    }

    console.log('processing file ', file);
    res.status(200).send({});
  } catch (e) {
    res.status(500).send(e);
  }
});

What was the result you got?

The form.parse callback is never called.

What result did you expect?

The form.parse callback is called.

This seems similar to issue https://github.com/node-formidable/formidable/issues/396.

Wrapping the form.parse in a Promise is the recommended solution but it hasn't worked for me

What can I do to understand what's happening under the covers?

tunnckoCore commented 4 years ago

Yes, known issue. Use the package serverless-formidable. It will be integrated and handled in the next major release, so stay tuned and update to it when it's out of canary/beta.

helloforward commented 4 years ago

Great news, thx!

helloforward commented 4 years ago

@tunnckoCore I tried the latest canary release of formidable but that didn't work so maybe it's not currently in there. When do you think roughly the next major release will be?

lexNwimue commented 1 year ago

Had this same issue too, when I deployed my code to Google Cloud using Firebase Functions. Only had it fixed when I used formidable-serverless-2. Thanks, guys!

czmarcos commented 1 year ago

@lexNwimue do you have the link of this package? I did not found it. Thanks

lexNwimue commented 1 year ago

https://www.npmjs.com/package/formidable-serverless-2

There's also https://www.npmjs.com/package/formidable-serverless. But I didn't use this. I dunno if this is any different