在React Native中,我可以使用带有<Image source={{uri: 'http://my.server.com/user/id/image/id.png'}} />
个字符的图像
问题是,用户图像受到JWT令牌的保护,我将其传递到头部.
是否有可能以某种方式包含额外的标题?
我的其他 Select 是什么?
谢谢
在React Native中,我可以使用带有<Image source={{uri: 'http://my.server.com/user/id/image/id.png'}} />
个字符的图像
问题是,用户图像受到JWT令牌的保护,我将其传递到头部.
是否有可能以某种方式包含额外的标题?
我的其他 Select 是什么?
谢谢
您的选项如下:https://rnplay.org/apps/UowZmw(为了查看模拟器,在dev控制台中键入document.querySelector('.editor-container').style.width = '50%'
,RNPlay的内容有点冗长).
基本上你要做的是:
在你的componentWillMount()
分钟内做到这一点:
fetch(YOUR_IMAGE_URI, {
method: 'GET',
headers: {
'Authorization': 'Bearer ' + 'TOKEN'
}
}
).then((res) => res.text())
.then((content) => {
this.setState({
base64: content
})
})
你可能注意到我用res.text()
而不是res.blob()
.这是因为,在写这篇文章时,RN不支持.blob().
这是render()
:
return (
<Image style={styles.base64} source={{uri: this.state.base64}} />
)