axios: onUploadProgress not being called

I am setting up an axios request like so:

  const form = new FormData()

  form.append('file', fileObject)

  axios.request({
    url:              url,
    data:             form,
    method:           'post',
    responseType:     'json',
    validateStatus:   function (status) {
      return status === 201
    },
    onUploadProgress: function (progressEvent) {
      console.log(progressEvent) 
    }
  })

data is a FormData object file a file resource, the data gets posted to my server correctly, but onUploadProgress never gets called, even when uploading large files (I only need to use it to upload images, just using large files for testing).

About this issue

  • Original URL
  • State: closed
  • Created 8 years ago
  • Reactions: 8
  • Comments: 28 (12 by maintainers)

Most upvoted comments

onUploadProgress is working well for me on iOS, but doesn’t seem to be firing at all on Android.

Here’s my code:

let response = await axios({
  method: 'post',
  url: imageUploadUrl,
  data: {
    connectorId,
    data
  },
  onUploadProgress: (progressEvent) => {
    const { loaded, total } = progressEvent;
    dispatch(updateImageUploadProgress(loaded, total));
  },
  cancelToken: new CancelToken(token => {
    cancelAxiosRequest = token;
  })
});

Please, test this example: https://jsfiddle.net/v70kou59/1/ . Select a file and click upload.