Skip to main content
edited tags
Link
200_success
  • 144.2k
  • 22
  • 188
  • 473
Bumped by Community user
Bumped by Community user
Removed concerns about the code from the title
Link
pacmaninbw
  • 24.8k
  • 11
  • 46
  • 109

What is the best way to upload Upload multiple images using react and axios?

Source Link

What is the best way to upload multiple images using react and axios?

I trying to upload multiple images about (5000 of size upto 50mb) and trying to figure out what would be the best way to do it.

right now i have this code:

  if (files.length) {
    files.forEach(file => {
      const formPayload = new FormData()
      formPayload.append('file', file.file)

      try {
         axios({
          baseURL: 'http://localhost:5000',
          url: '/file',
          method: 'post',
          data: formPayload,
          onUploadProgress: progress => {
            const { loaded, total } = progress

            const percentageProgress = Math.floor((loaded / total) * 100)
            dispatch(setUploadProgress(file.id, percentageProgress))
          },
        })
        dispatch(successUploadFile(file.id))
      } catch (error) {
        dispatch(failureUploadFile(file.id))
      }
    })
  }

but it uploads all images at once, it is alright to do so?