在React Native中将base64字符串转换为图像 [英] Convert base64 string to image in react native

查看:949
本文介绍了在React Native中将base64字符串转换为图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了一个具有expo's react native的社交媒体应用,并希望增加上传图片的功能.由于expo不允许您将文件转换为Blob进行上传,因此我只是将base64图像数据作为字符串上传到服务器数据库.从服务器外下载数据后,如何将这些数据再次转换为可见图像?

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?

推荐答案

您可以执行以下操作:

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

base64Icon变量中,您需要将base64数据放在data:image/png;base64,之后.像这样:

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}';

这篇关于在React Native中将base64字符串转换为图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆