1

我已经成功地从 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" }

4

1 回答 1

1

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

例如:

<Image source={this.state.source} style={{width: 100, height: 100}} /> 
于 2019-06-25T06:00:08.697 回答