flutter:[firebase_storage/unknown]出现未知错误,请检查服务器响应

mtb9vblg  于 2023-02-05  发布在  Flutter
关注(0)|答案(1)|浏览(141)

从IOS模拟器,我应该看到“成功”作为响应后,选择头像图像,输入用户名,电子邮件,密码,和个人简介.然而,我一直得到这个错误响应,像这样:[firebase_storage/unknown]发生未知错误,请检查服务器响应。
[更新]我能够通过编辑Firebase存储规则来解决这个问题,方法是省略“:如果为假”修改为:

rules_version = '2';
service firebase.storage {
  match /b/{bucket}/o {
    match /{allPaths=**} {
      allow read, write;
    }
  }
}
nnsrf1az

nnsrf1az1#

只需将.putfile更改为.putdata即可修复此错误,同时检查存储规则。

final ImagePicker picker = ImagePicker();
final XFile? image = await picker.pickImage(source: ImageSource.gallery);
imgFile = File(image!.path);

UploadTask uploadTask;
Reference ref = FirebaseStorage.instance.ref().child('books').child('/hogehoge.jpg');

try {
  uploadTask = ref.putData(await imgFile.readAsBytes());
  imgUrl = await (await uploadTask).ref.getDownloadURL();
} catch (e) {
  print(e.toString());
}

相关问题