joltup / rn-fetch-blob

A project committed to making file access and data transfer easier, efficient for React Native developers.
MIT License
2.81k stars 772 forks source link

uploadProgress callback is not working #670

Closed jpmazza closed 3 years ago

jpmazza commented 3 years ago

Working on a react-native app, I'm having the following issue in both platforms (iOS and Android)

Environment:

"react-native": "^0.61.1",
"rn-fetch-blob": "^0.12.0"

I'm doing a multipart request to upload a video to the server. Given this request takes time I would like to show the progress to the user.

According to the library documentation, there is a uploadProgress callback: https://github.com/joltup/rn-fetch-blob#uploaddownload-progress but is not working on my side.

Here is my code:

RNFetchBlob.fetch(
    'POST',
    `${REACT_APP_API_DOMAIN}/upload/video`,
    {
      Authorization: `Bearer ${token}`,
      timestamp: `${timestamp}`,
      'Content-Type': 'multipart/form-data',
    },
    [
      {
        name: 'video',
        filename: `video.${file.split('.')[file.split('.').length - 1]}`,
        data: RNFetchBlob.wrap(file),
      },
    ],
  )
    .then(() => {
      Notifier.showNotification({
        title: 'The videos was successfully saved!',
        description: "We're processing it, your profile will be updated soon!",
        Component: NotifierComponents.Alert,
      });
      setStatus(statusEnum.PROCESSING);
      completeCallback();
    })
    .uploadProgress((written, total) => {
      console.log('uploaded', written / total);
    })
    .catch(err => {
      Notifier.showNotification({
        title: 'There was an error uploading the video',
        description: err.toString(),
        Component: NotifierComponents.Alert,
        componentProps: {
          alertType: 'error',
        },
      });
      setStatus(statusEnum.FAILED);
      completeCallback();
    });

Any thoughts?

cpecorari commented 3 years ago

The uploadProgress works for me, though i have it right after the fetch : .fetch(...).uploadProgress(...).then(...) Tried this ?

jpmazza commented 3 years ago

Thank you @cpecorari !!