_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:27at MessageQueue.__invokeCallback (blob:http://localhost:19001/e9d43477-4e42-4f7a-b494-16485def4c28:2765:18)at blob:http://localhost:19001/e9d43477-4e42-4f7a-b494-16485def4c28:2510:18at 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编码为’%’,导致putfile代码找不到该文件.在uri周围添加decodeURI调用修复了问题.let fileUri = decodeURI(pickerResult.uri)总结
以上是内存溢出为你收集整理的ios – React Native Firebase存储上载因未知错误而失败全部内容,希望文章能够帮你解决ios – React Native Firebase存储上载因未知错误而失败所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)