Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

112
Views
How to handle async file upload in react-dropzone?

In my app, I have a separate Uploader component based on react-dropzone, which has a handleFileUpload method. I forward it with useEffect as a reference to the parent component and trigger it there when the Submit button is clicked.

I tried a very basic approach to upload multiple files into S3 with pre-signed URLs using Fetch API.

Uploader.js

const handleFileUpload = async () => {
  console.log("handleFileUpload begin");
    for (const file of files) {
      let url = await getPresignedUrl(file.name);
      let response = await fetch(url, {
        method: "PUT",
        body: file,
      });
      console.log(response) // <- this is never triggered
    }
  };
  console.log("handleFileUpload end");
};

In the parent Form component, I run this forwarded method asynchronously on form submit using a React callback.

Form.js

const handleSubmit = useCallback(
  async (e) => {
    e.preventDefault();

      // upload files using ref to the method from Uploader component
    await handleUpload.current().then(
      console.log('file uploaded')

      // update item in database
      ...
    )
  },
[handleUpload]
);

What I see is that all console logs are executed in the expected order, except for the actual fetch call. So files are never uploaded when I hit the Submit button. I want to be sure that my files are finished uploading to the server before I update any database entries, etc. There must something wrong with my approach, am I using the async calls correctly?

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!