使用react-native-image-picker将图片上传到firebase [英] Upload image to firebase using react-native-image-picker

查看:837
本文介绍了使用react-native-image-picker将图片上传到firebase的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在尝试使用firebase,React Native和react-native-image-picker来上传图片。

我从图片选择器获得的数据是在base64格式,我不知道如何实际上传到我的firebase存储,因为当我执行以下行:

  var imageRef = storageRef.child(images / usersImages /+ global.userID +.jpg)
uploadTask = imageRef.put(global.imageToUpload)

之后没有执行任何操作。即使我之后立即发出警报。
我的«file»变量包含:'data:image / jpeg; base64,'+ response.data



我也试着只放入response.data,但是不起作用。

解决方案

从我上次阅读这里,Firebase不支持从 react-native 作为二进制文件上传图片。但是,您可以将base64编码的图像直接存储在firebase中。这就像将任何其他字符串存储在firebase中一样。尽管像这样直接在firebase上存储图像,但是小于10 MB 的限制。


I’ve been trying to upload an image using firebase, React Native and react-native-image-picker.

The data I get from the image picker is in base64 format and I don’t know how to actually upload it to my firebase storage because when I execute the following line :

var imageRef = storageRef.child("images/usersImages/" + global.userID + ".jpg")
uploadTask = imageRef.put(global.imageToUpload)

Nothing is executed after. Even if I put an alert right after. My « file » variable contains that : 'data:image/jpeg;base64,' + response.data

I’ve also tried to put only the response.data but it’s not working.

解决方案

From what I read last here, Firebase doesn't support uploading images as binaries from react-native. However, you can store the base64 encoded image directly in firebase. It would be like storing any other string in firebase. There is a limit of less than 10 MB though while storing image directly on firebase like this.

这篇关于使用react-native-image-picker将图片上传到firebase的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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