next-s3-upload icon indicating copy to clipboard operation
next-s3-upload copied to clipboard

Multiple files upload: isComplete

Open marcosantonocito opened this issue 1 year ago • 2 comments

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!

marcosantonocito avatar Apr 04 '23 07:04 marcosantonocito

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.

ryanto avatar Apr 08 '23 01:04 ryanto

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
        })()
    }
};

software0012 avatar Oct 29 '23 20:10 software0012