没有触发uploadProgress rn-fetch-blob

问题描述

在使用本机应用程序时,两个平台(iOS和Android)都遇到以下问题

环境:

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

我正在执行一项将视频上传到服务器的多部分请求。鉴于此请求需要时间,我想向用户显示进度。

根据库文档,有一个uploadProgress回调:https://github.com/joltup/rn-fetch-blob#uploaddownload-progress,但对我而言不起作用。

这是我的代码

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(),componentProps: {
          alertType: 'error',});
      setStatus(statusEnum.Failed);
      completeCallback();
    });

有什么想法吗?

解决方法

此问题已在此处回答:https://github.com/joltup/rn-fetch-blob/issues/670#issuecomment-696016355

基本上,我不得不交换thenuploadProgress回调。

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...