Convert base64 string to image in react native

落爺英雄遲暮 提交于 2019-12-01 01:43:15

问题


Problem

I created a social media app with expo's react native, and wanted to add the ability to upload images. Since expo won't let you convert a file to a blob to upload, I just uploaded the base64 image data as a string to the server database. How can I convert this data into the viewable image again after I download the data from off of the server?


回答1:


You can do this:

var base64Icon = 'data:image/png;base64,iVBORw0KGgoAAAANS...';
<Image style={{width: 50, height: 50}} source={{uri: base64Icon}}/>

In the base64Icon variable you need to put your base64 data after data:image/png;base64,. Like this:

var base64Icon = 'data:image/png;base64,{PLACE_YOUR_BASE64_DATA_HERE}';


来源:https://stackoverflow.com/questions/48134980/convert-base64-string-to-image-in-react-native

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!