【发布时间】:2020-02-03 11:29:19
【问题描述】:
我正在使用 rn-fetch-blob 获取 api 并将文件直接下载到我的存储中,已经创建了一个路径,我现在可以成功下载它但是当我尝试打开文件时,它显示:'无法打开文件'
下面是我的下载功能:
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())
})
}
}
我已经在我的下载图标的平面列表中调用了这个函数,如下所示:
<TouchableOpacity
onPress= {() => this.download(item)}
style={{
alignItems: 'center',
borderRadius: 60,
padding: 10,
}}>
<Icon name="download" size={30} color="white" />
</TouchableOpacity>
谁能告诉我为什么会这样? 我已经更新了依赖项并添加了权限。 如果您还需要什么,请告诉我。
【问题讨论】:
标签: reactjs react-native react-native-android react-native-flatlist