0

I have added one feature around 1 month ago, which show progress of uploading file that time axios onUploadProgress is totally working fine, but now its not even get called when I am uploading file

code:

   axios.post(`${process.env.REACT_APP_BEHOST}/user/upload`, formData, {
            headers: {
                'Authorization': `Bearer ${user.token}`
            },
            onUploadProgress: ({ loaded, total }) => {
                setShowModal(true)
                setProgress(Math.floor((loaded * 100) / total))

            }
        })

Please can someone Tell me whats wrong in this

1 Answers1

0

I also have a progress bar that shows how much of the upload has been completed. But I am doing it a little different maybe it will help you.

First of all I create a config object with onUploadRequest which I later on just add to my axios request:

const config = {
    signal: controller.value.signal,
    onUploadProgress: (progressEvent) => {
      percentCompleted.value = Math.round(
        (progressEvent.loaded / progressEvent.total) * 100
      )
    }
  }

axios.put(
  `${url}/${messageUuid}file/${file.value.files[0].name}`,
  config
)
.then(() => {
  alert('Completed')
})

I left out a lot of unnecessary code. Hope it can somehow help you!

Fersek
  • 37
  • 1
  • 6