![](/img/trans.png)
[英]Can't write to bind mount on ECS Fragate when using non-root user
[英]The operation 'uploadBytesResumable' cannot be performed on a root reference, create a non-root reference using child
我正在使用 Firebase 服务,没有这样的测试规则: allow read, write: if true;
当我决定制定规则时,这个问题突然发生了!
allow read, write: if request.auth;= null;
FirebaseError:Firebase 存储:无法对根引用执行“uploadBytesResumable”操作,使用 child 创建非根引用,例如 .child('file.png')。 (存储/无效根操作)
在更改规则之前,我将许多图像上传到存储中并在我的应用程序中查看它们,但现在我正在尝试不做任何更改地使用我的所有信息!!
这是我用来上传图片的方法,我在更改规则之前或之后都没有更改任何内容:
Reference reference = FirebaseStorage.instance.ref();
Future uploadImage() async {
reference.child('Items/${itemNameController.text}.jpg');
await reference.putData(
webImage!,
SettableMetadata(contentType: 'image/jpeg'),
);
downloadUrl = await reference.getDownloadURL();
update();
}
顺便说一句,我正在使用 Flutter web。
我正在使用这个 package: firebase_storage firebase_storage: ^11.0.6
我将把我的操作的完整代码放在这里,当我尝试上传到 fireStorage 时出现问题,但还有另一个 function 将数据存储在 fireStore 中。
我已经尝试过某人输入的解决方案,但是当我将函数 (FireStorage - FireStore) 相互组合时仍然遇到同样的问题:
Database database = Database();
String? id;
Future saveToDb() async {
var formData = formKey.currentState;
if (formData!.validate()) {
await uploadImage().whenComplete(() async {
await addToFireStore();
clearData();
Get.snackbar(
'Adding done',
'Adding item done successfully',
snackPosition: SnackPosition.BOTTOM,
backgroundColor: AppColors.mainColor,
borderRadius: Dimensions.radius20,
duration: const Duration(seconds: 3),
padding: EdgeInsets.fromLTRB(
Dimensions.width30,
Dimensions.height20,
Dimensions.width40,
Dimensions.height20,
),
);
update();
});
}
}
Future uploadImage() async {
await database.reference.child('Items/${itemNameController.text}.jpg').putData(
webImage!,
SettableMetadata(contentType: 'image/jpeg'),
);
downloadUrl = await database.reference.getDownloadURL();
update();
}
Future addToFireStore() async {
for (var i in database.categoriesModel) {
if (database.categoryValue == i.name) {
id = i.id;
}
}
await database.catCollectionRef
.doc(id)
.collection('Items')
.doc(const Uuid().v4())
.set({
'id': const Uuid().v4(),
'Name': itemNameController.text,
'Decryption': itemDescController.text,
'Availability': switchValue.toString(),
'Category': database.categoryValue,
'Quantity type': quantityValue,
'Quantity value': itemQuanController.text,
'Price': itemPriceController.text,
'Image': downloadUrl,
});
update();
}
clearData() {
webImage?.clear();
itemNameController.clear();
itemDescController.clear();
itemQuanController.clear();
itemPriceController.clear();
database.categoryValue = 'Choose one';
switchValue = false;
quantityValue = 'Choose One';
downloadUrl = '';
update();
}
我在 UI 按钮中使用saveToDb()
function 来设置整个操作,但返回同样的问题!
您引用的是根 directlt,调用child()
on 语句不会更改引用,请尝试:
Reference reference = FirebaseStorage.instance.ref();
Future uploadImage() async {
await reference.child('Items/${itemNameController.text}.jpg').putData(
webImage!,
SettableMetadata(contentType: 'image/jpeg'),
);
downloadUrl = await reference.getDownloadURL();
update();
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.