next-s3-upload
next-s3-upload copied to clipboard
Multiple files upload: isComplete
Hello and thank you for your fantastic work!
Is there any way to understand when a multiple files upload is completed? I want to trigger an event when the upload is completed but I can't find a way to do it.
Thank you!
Thanks! I think the best way would be to track all the promises returned by uploadToS3()
then then await Promise.all(uploadPromises)
to know when they're done.
If you want to share some sample code from your app I can take a look.
Hi,
Here's a way to do it.
useEffect(() => { if(files.every((file) => file.progress == 100)){ // All files were uploaded successfully. } }, [files]);
Bonus:
If you want to upload multiple files at the same time instead of waiting for all promises, I would suggest doing it this way:
const handleFilesChange = async ({target}) => {
const files = Array.from(target.files);
for (let index = 0; index < files.length; index++) {
const file = files[index];
(async () => {
await uploadToS3(file);
// Do something if needed
})()
}
};