File cannot open after download on Android

自古美人都是妖i 提交于 2020-05-17 06:40:21

问题


I have used rn-fetch-blob to fetch api and download a video, the video is getting downloaded successfully however, when I try to open the file, it shows me :'file cannot open', it is a mp4 format, and is running otherwise, I have checked the file separately.

Below is the download function:

download = async (item) => {
  console.log(item)
  const granted = await PermissionsAndroid.request(PermissionsAndroid.PERMISSIONS.WRITE_EXTERNAL_STORAGE)
  if (granted === PermissionsAndroid.RESULTS.GRANTED) {
    let dirs = RNFetchBlob.fs.dirs;
    RNFetchBlob.config({
      fileCache: true,
      addAndroidDownloads: {
        useDownloadManager: true,
        notification: true,
        path: dirs.DownloadDir + "/Baaz_" + Math.random().toString().slice(2, 6),
        mime: 'application/mp4',
        mediaScannable: true,
      }
    }).fetch('GET', 'some url' + item.nameVid, { 'Cache-Control': 'no-store' }).then((res) => {
      alert('The file has saved!')
      console.log('The file saved to ', res.path())
    })
  }
}

I have called this function as below,

<TouchableOpacity
  onPress= {() => this.download(item)}
  style={{
    alignItems: 'center',
    borderRadius: 60,
    padding: 10,
  }}>
    <Icon name="download" size={30} color="white" />
</TouchableOpacity>

When I open the downloaded file, it shows me cannot open file, why is it so? Please, tell me if you need anything else and help.

来源:https://stackoverflow.com/questions/60039755/file-cannot-open-after-download-on-android

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!