首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >通过react-native-fs库下载后,图像不会出现在手机中

通过react-native-fs库下载后,图像不会出现在手机中
EN

Stack Overflow用户
提问于 2018-12-19 14:23:12
回答 1查看 689关注 0票数 1

我已经使用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 }) });

有人能帮我解决这个问题吗?

EN

回答 1

Stack Overflow用户

发布于 2019-08-26 21:06:07

代码语言:javascript
复制
  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);
        });
      });
    }
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/53845614

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档