How to wait for all uploads to finish before returning #884
-
I can't figure out how to get How do I only return a response once all the files have successfully gone through the 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();
});
}); |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
proimisy the s3Client.upload function, store the promise in a variable, push the variable in an array, then |
Beta Was this translation helpful? Give feedback.
proimisy the s3Client.upload function, store the promise in a variable, push the variable in an array, then
use
await Promise.all(promises)