Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings
Discussion options

I can't figure out how to get formidable to wait until all the uploads are done before returning a response. Specifically I am using S3 for handling uploads, and following the example code here: https://github.com/node-formidable/formidable/blob/master/examples/store-files-on-s3.js

How do I only return a response once all the files have successfully gone through the fileWriteStreamHandler? There doesn't seem to be any support for Promises nor callbacks in there.

I was expecting something like this:

const uploadStream = (file) => {
  const pass = new PassThrough();
  s3Client.upload(
    {
      Bucket: 'demo-bucket',
      Key: file.newFilename,
      Body: pass,
    },
    (err, data) => {
      // I want to add something here to capture the response and also tell formidable not to exit
      // until we get here.
    },
  );

  return pass;
};

const server = http.createServer((req, res) => {
    const form = formidable({
      fileWriteStreamHandler: uploadStream,
    });

    form.parse(req, () => {
      // I only want this to fire once all the files have completed uploading to S3. Ideally
      // I also want to access the results from the S3 upload as well so I can include the S3
      // response data in the endpoint return response
      res.writeHead(200);
      res.end();
    });
});
You must be logged in to vote

proimisy the s3Client.upload function, store the promise in a variable, push the variable in an array, then
use await Promise.all(promises)

Replies: 1 comment · 1 reply

Comment options

proimisy the s3Client.upload function, store the promise in a variable, push the variable in an array, then
use await Promise.all(promises)

You must be logged in to vote
1 reply
@EvHaus
Comment options

Thanks for the response. It's not the cleanest solution but it will do the trick. :)

Answer selected by EvHaus
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
🙏
Q&A
Labels
None yet
2 participants
Morty Proxy This is a proxified and sanitized view of the page, visit original site.