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();
});
}); |
Answered by
GrosSacASac
Sep 10, 2022
Replies: 1 comment · 1 reply
|
proimisy the s3Client.upload function, store the promise in a variable, push the variable in an array, then |
1 reply
Answer selected by
EvHaus
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
proimisy the s3Client.upload function, store the promise in a variable, push the variable in an array, then
use
await Promise.all(promises)