我已经使用react-native-fs库通过我的应用程序下载了图像。下载显示已完成,但图像仍未显示在手机中的任何位置。该文件夹显示修改日期,但那里没有图像。
我调用的函数:
RNFS.downloadFile({ fromUrl: 'https://facebook.github.io/react-native/img/header_logo.png', toFile: '${RNFS.DocumentDirectoryPath}/react-native-hello.png', }).promise.then((r) => { console.log("download done"); this.setState({ isDone: true }) });
有人能帮我解决这个问题吗?
发布于 2019-08-26 21:06:07
Try this code:
actualDownload = () => {
let url = 'https://facebook.github.io/react-native/img/header_logo.png'
let name = 'logo.png'
let dirs = RNFS.DocumentDirectoryPath/MyApp;
console.log("--path--",dirs)
const file_path = dirs +'/'+name
RNFS.readFile(url, 'base64')
.then(res =>{
this.setState({resBase64:res})
let base64 = this.state.resBase64
RNFS.writeFile(file_path,base64,'base64')
.catch((error) => {
console.log("err",error);
});
});
}https://stackoverflow.com/questions/53845614
复制相似问题