问题
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