Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/xamarin/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios React本机Firebase存储上载失败,出现未知错误_Ios_Firebase_React Native_Firebase Storage_React Native Firebase - Fatal编程技术网

Ios React本机Firebase存储上载失败,出现未知错误

Ios React本机Firebase存储上载失败,出现未知错误,ios,firebase,react-native,firebase-storage,react-native-firebase,Ios,Firebase,React Native,Firebase Storage,React Native Firebase,我使用Firebase帐户进行身份验证、firestore和存储。尝试将照片上载到存储器失败,出现未知错误。以下是尝试的代码: _pickImage = async () => { await this.getCameraRollPermission() let result = await ImagePicker.launchImageLibraryAsync({ allowsEditing: true, aspect: [4, 3], }); cons

我使用Firebase帐户进行身份验证、firestore和存储。尝试将照片上载到存储器失败,出现未知错误。以下是尝试的代码:

_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文件最终出现在bucket中,而不是实际的照片,然后抛出错误

此问题似乎被跟踪了几次,但没有得到解决:


终于找到了我的问题。来自ImagePicker的图像的URI中包含来自本地应用缓存的“%”字符。此百分比被URI编码为“%25”,这导致putFile代码找不到该文件。在uri周围添加decodeURI调用修复了该问题

let fileUri = decodeURI(pickerResult.uri)

如果您使用的是react native document picker,请检查以下内容:

@GavinThomas我查看了该链接,该链接表明问题可能是将blob传递给putFile函数而不是文件路径,但我从state传递的photoURL是模拟器中的文件url:
"file:///Users/username/Library/Developer/CoreSimulator/Devices/14BB3E6A-883D-4E7B-A5AE-7F5D20F82A53/data/Containers/Data/Application/0555717C-3B90-4A19-8EA4-BA303F903D86/Library/Caches/ExponentExperienceData/%2540username%252Fapp-名称/图像选择器/59FD4C19-D7CF-490B-9F9F-B449CD5914A6.jpg“
也许你可以发布你如何从设备上传照片的代码。也许它实际上并没有给你这个斑点?这里有一个链接到我的工作照片采集器上传到firebase,实际上传的动作(你共享的代码)在actions文件夹中。我查看了您的代码,但由于您使用的是firebase库,而不是react native firebase,因此我不确定它是否翻译得很好。我的选择器代码非常标准,只是ExpoKit中的ImagePicker。我已经更新了代码以显示ImagePicker部分。您使用的是哪种React本机版本?解码现在在React本机firebase的后续版本中自动完成-因此这不再是一个问题。