[英]Unhandled Exception: [firebase_storage/unauthorized] User is not authorized to perform the desired action
[英]Fire Storage Exception ([firebase_storage/unauthorized] User is not authorized to perform the desired action.) (my rule is allow read/write)
我正在嘗試從 firebase firestore 獲取圖像,同時嘗試獲取圖像下載 url 有這個例外:
W/StorageUtil(10206):請求沒有授權令牌
(有此錯誤的類似問題不能解決問題)
盡管我的安全規則允許讀寫,但我仍然收到此錯誤。
有什么想法嗎?
獲取圖像 url 的代碼:
static Future<dynamic> loadImage(BuildContext context, String image) async {
return await FirebaseStorage.instance.ref().child(image).getDownloadURL();
}
調用此 loadImage function:
Future<Widget> getImage(BuildContext context, String imgName) async {
Image image;
await FireStorageService.loadImage(context, imgName).then((value) {
print(value);
image = Image.network(value.toString(), fit: BoxFit.scaleDown);
return image;
});
}
調用此 getImage function:
child: FutureBuilder(
future: getImage(context, "/images/test1.jpg"),
...
)
我的firebase存儲規則:
rules_version = '2';
service firebase.storage {
match /images/{imageId} {
allow read,write;
}
}
存儲規則 ss:
導航到 Firebase 控制台
在開發開放存儲下的側邊欄中
打開規則選項卡將控制台上的規則替換為以下規則:
rules_version = '2'; service firebase.storage { match /b/{bucket}/o { match /{allPaths=**} { allow read, write } } }
並發布完成
我通過更改規則來修復它。
Go 到 Firebase 項目>存儲>規則。
默認情況下,您不允許在 Firebase 上上傳,因此您必須更改它。
rules_version = '2';
service firebase.storage {
match /b/{bucket}/o {
match /{allPaths=**} {
allow read, write: if false;
}
}
}
更改allow read, write: if false;
allow read, write;
(2022):最近,我通過遵循 Firestore 基本安全規則(針對經過身份驗證的用戶)解決了問題:
service firebase.storage {
match /b/{bucket}/o {
match /{allPaths=**} {
allow read, write: if request.auth != null;
}
}
}
你可以在他們的網站上看到這個: https://firebase.google.com/docs/rules/basics?authuser=1#cloud-storage_1
我不建議使用 allow read, write; 直接地。 如果您的應用程序有身份驗證,那么您需要檢查 auth 是否為 null。
Go 到 Project Settings -> App Check -> Products Change the Storage from Enforce -> Unenforced
通過更改 firebase 中的規則,這對我有用。
rules_version = '2';
service firebase.storage {
match /b/{bucket}/o {
match /{allPaths=**} {
allow read, write
}
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.