React Native RNFetchBlob下载文件的大小为0 Kb

时间:2020-05-12 20:18:55

标签: react-native file download rn-fetch-blob

我正在尝试使用RNFetchBlob使用React Native下载文件。 下载成功,但文件大小为0 Kb,我无法打开它。

这是我的职能,我做错了什么?

    let dirs = RNFetchBlob.fs.dirs

  await  RNFetchBlob.fs.isDir(dirs.DocumentDir+"/"+this.props.navigation.getParam('urlPlanche'))
    .then( async (isDir) => {
        //Create the folder if not
      await  RNFetchBlob.fs.mkdir(dirs.DocumentDir+"/"+this.props.navigation.getParam('urlPlanche'))
        .then(async () => {
          //Download file
          let size = this.state.fichiers.length
          await AsyncStorage.setItem("size"+this.props.navigation.getParam('urlPlanche'),size.toString())
          for(let i=0; i<size;i++)
          {
          await  RNFetchBlob
            .config({
              fileCache: true,
              path : dirs.DocumentDir+"/"+this.props.navigation.getParam('urlPlanche')+"/"+
              this.state.fichiers[i].imagePlanche
            })
            .fetch('GET', IMG_ADDR+'/'+this.state.fichiers[i].imagePlanche, {
              //some headers ..
            })
            .then(async (res) => {
              // the path should be dirs.DocumentDir + 'path-to-file.anything'
              //Some AsyncStorage setItem here
              console.log('The file saved to ', res.path())
            })
          }
        })
        .catch((err) => {
          alert("Erreur 1"+err)
          console.log('Erreur '+err)
         })
    })

  }```

The progress show directly 1 (it means 100%). Must I add appendfile or something like that?
I also try it with appendExt and without await.

0 个答案:

没有答案