【问题标题】:Can't display downloaded image from RNFS.DocumentDirectoryPath无法显示从 RNFS.DocumentDirectoryPath 下载的图像
【发布时间】:2019-06-25 05:01:53
【问题描述】:

我已成功保存来自 url 的图像和响应 {“jobId”:1,“statucCode”:200,“byteWritten”:127744 }

但我无法显示图像。

下载文件(){

var RNFS = require('react-native-fs');

const uri = 'https://images.unsplash.com/photo-1525184275980-9028ceb8e09f?auto=format&fit=crop&w=1050&q=80' ; 
const name = shorthash.unique(uri);
const path = `${RNFS.DocumentDirectoryPath}/${name}.png`;

RNFS.downloadFile({fromUrl:uri, toFile: path}).promise
    .then((res) => { 
        this.setState({ source:{uri:path}}) ;
    }).catch((err) => { 
        alert(err)
     });
}

状态将类似于 source : { "uri" : "path" }

【问题讨论】:

  • @Tim 我已经用我创建的下载文件功能更新了问题,然后将路径设置为状态源
  • 你想如何显示图像?
  • 您是否指定图像的高度和宽度?

标签: react-native react-native-android react-native-ios react-native-fs


【解决方案1】:

您的代码似乎是正确的,但您可能缺少为图像指定宽度和高度。

例如:

<Image source={this.state.source} style={{width: 100, height: 100}} /> 

【讨论】:

    猜你喜欢
    • 2011-09-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-05-31
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-04-08
    相关资源
    最近更新 更多