我在我的反应本机项目中有以下获取函数来从 MS Graph 返回一个 blob 图像,返回有效,但我似乎无法将 blob 显示为图像。
//Blob Picture
fetch('https://graph.microsoft.com/v1.0/me/photo/$value', {
headers: { 'Authorization': "Bearer " + accessToken },
})
.then((response) => {
// console.log(response);
this.setState({ BlobImage: response});
})
.catch((error) => {
console.error(error);
});
然后我希望像这样显示图像:
<Image source={{uri: BlobImage}} style={{ height: 200, width: null, flex: 1 }}/>
一种方法是你的BLOB转换为Base64和描述用它作为URI在这里,但我宁愿使用RN取二进制大对象,并使用路径,因为是更直截了当。检查这个例子:
RNFetchBlob
.config({
fileCache : true,
// by adding this option, the temp files will have a file extension
appendExt : 'png'
})
.fetch('GET', 'http://www.example.com/file/example.zip', {
//some headers ..
})
.then((res) => {
// the temp file path with file extension `png`
console.log('The file saved to ', res.path())
// Beware that when using a file path as Image source on Android,
// you must prepend "file://"" before the file path
imageView = <Image source={{ uri : Platform.OS === 'android' ? 'file://' + res.path() : '' + res.path() }}/>
})
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句