[我试图查看存储在Firebase存储器中的图像,但是当我使用<Image />
的源道具中的下载网址时,会收到警告:
警告:道具类型失败:提供给
source
的道具Image
无效。
上传功能:
const Blob = RNFetchBlob.polyfill.Blob;
const fs = RNFetchBlob.fs;
window.XMLHttpRequest = RNFetchBlob.polyfill.XMLHttpRequest;
window.Blob = Blob;
uploadImage = async (uri, mime = "application/octet-stream") => {
if (this.state.uploadable == "") {
alert("No image selected");
} else {
const uploadUri =
Platform.OS === "ios" ? uri.replace("file://", "") : uri;
const sessionId = new Date().getTime();
let uploadBlob = null;
const imageRef = firebase
.storage()
.ref("userSpecificFolder")
.child("profileImage");
fs.readFile(uploadUri, "base64")
.then(data => {
return Blob.build(data, { type: `${mime};BASE64` });
})
.then(blob => {
uploadBlob = blob;
return imageRef.put(blob, { contentType: mime });
})
.then(() => {
uploadBlob.close();
return imageRef.getDownloadURL();
})
.then(url => {
this.setState({ storedImg: url });
resolve(url);
})
.catch(err => {
reject(err);
});
}
};
下载功能:
downloadImg = () => {
firebase
.storage()
.ref("userSpecificFolder/profileImage")
.getDownloadURL()
.then(url => {
this.setState({ storedImg: url });
});
};
实施:
<View>
<Image source={this.state.storedImg}/>
</View>
如果这不是从Firebase存储中查看图像的方法,缺少哪些步骤?
ps,香港专业教育学院尝试发布的答案与上述相同的结果here。
问题在于实施。由于某种原因,URL需要是对象中uri属性的值。 <Image source={{uri: *url* }} />
并显示图像。