React Native Firebase Storage Upload fails with Unknown error(Reaction本机Firebase存储上载失败,出现未知错误)
本文介绍了Reaction本机Firebase存储上载失败,出现未知错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用react-native-firebase使用我们的Firebase帐户进行身份验证、防火墙存储和存储。尝试将照片上载到存储失败,出现未知错误。以下是尝试的代码:_pickImage = async () => {
await this.getCameraRollPermission()
let result = await ImagePicker.launchImageLibraryAsync({
allowsEditing: true,
aspect: [4, 3],
});
console.log(result);
if (!result.cancelled) {
// this.setState({ photoURL: result.uri });
this._handlePhotoChoice(result)
}
};
_handlePhotoChoice = async pickerResult => {
let userId = this.state.userId
firebase
.storage()
.ref('photos/profile_' + userId + '.jpg')
.putFile(pickerResult.uri)
.then(uploadedFile => {
console.log("Firebase profile photo uploaded successfully")
})
.catch(error => {
console.log("Firebase profile upload failed: " + error)
})
}
在IOS模拟器中测试并使用调试器检测错误我只是得到此错误:
"Error: An unknown error has occurred.
at createErrorFromErrorData (blob:http://localhost:19001/e9d43477-4e42-4f7a-b494-16485def4c28:2371:17)
at blob:http://localhost:19001/e9d43477-4e42-4f7a-b494-16485def4c28:2323:27
at MessageQueue.__invokeCallback (blob:http://localhost:19001/e9d43477-4e42-4f7a-b494-16485def4c28:2765:18)
at blob:http://localhost:19001/e9d43477-4e42-4f7a-b494-16485def4c28:2510:18
at MessageQueue.__guardSafe (blob:http://localhost:19001/e9d43477-4e42-4f7a-b494-16485def4c28:2678:11)
at MessageQueue.invokeCallbackAndReturnFlushedQueue (blob:http://localhost:19001/e9d43477-4e42-4f7a-b494-16485def4c28:2509:14)
at http://localhost:19001/debugger-ui/debuggerWorker.js:70:58"
更新:
将文件上传到存储桶,但该文件不是JPEG照片,而是关于该文件的JSON内容:
{"contentType":"image/jpeg","name":"photos/profile_XPIO2lHjlYbdLPchACZHBsmY9Jr1.jpg"}
因此,不知何故,JSON文件最终出现在存储桶中,而不是实际的照片中,然后抛出错误。
此问题似乎已跟踪了几次,但未解决:
https://github.com/invertase/react-native-firebase/issues/1177
https://github.com/invertase/react-native-firebase/issues/302
推荐答案
终于找到我的问题了。来自ImagePicker的图像的URI中包含本地应用程序缓存中的‘%’字符。此百分比的URI编码为‘%25’,这导致putFile代码找不到该文件。在URI周围添加decdeURI调用已解决此问题。
let fileUri = decodeURI(pickerResult.uri)
这篇关于Reaction本机Firebase存储上载失败,出现未知错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
沃梦达教程
本文标题为:Reaction本机Firebase存储上载失败,出现未知错误
基础教程推荐
猜你喜欢
- 在 gmail 中为 ios 应用程序检索朋友的朋友 2022-01-01
- 如何让对象对 Cocos2D 中的触摸做出反应? 2022-01-01
- 如何在 iPhone 上显示来自 API 的 HTML 文本? 2022-01-01
- 当从同一个组件调用时,两个 IBAction 触发的顺序是什么? 2022-01-01
- Kivy Buildozer 无法构建 apk,命令失败:./distribute.sh -m “kivy"d 2022-01-01
- UIWebView 委托方法 shouldStartLoadWithRequest:在 WKWebView 中等效? 2022-01-01
- 如何在 UIImageView 中异步加载图像? 2022-01-01
- Android:对话框关闭而不调用关闭 2022-01-01
- android 应用程序已发布,但在 google play 中找不到 2022-01-01
- 如何在没有IB的情况下将2个按钮添加到右侧的UINavigationbar? 2022-01-01