使用 react-native-image-picker 将图像上传到 firebase

Upload image to firebase using react-native-image-picker

我一直在尝试使用 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 但没用。

根据我上次阅读的内容 here,Firebase 不支持从 react-native 上传图像作为二进制文件。但是,您可以将 base64 编码的图像直接存储在 firebase 中。这就像在 firebase 中存储任何其他字符串。虽然像这样直接在 firebase 上存储图像时有 less than 10 MB 的限制。