Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Multiple files upload: isComplete #143

Open
marcosantonocito opened this issue Apr 4, 2023 · 2 comments
Open

Multiple files upload: isComplete #143

marcosantonocito opened this issue Apr 4, 2023 · 2 comments
Labels
question Further information is requested

Comments

@marcosantonocito
Copy link

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!

@ryanto
Copy link
Owner

ryanto commented Apr 8, 2023

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 ryanto added the question Further information is requested label Apr 8, 2023
@software0012
Copy link

software0012 commented Oct 29, 2023

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

3 participants