简体   繁体   English

Fire Storage 异常([firebase_storage/unauthorized] 用户无权执行所需的操作。)(我的规则是允许读/写)

[英]Fire Storage Exception ([firebase_storage/unauthorized] User is not authorized to perform the desired action.) (my rule is allow read/write)

I am trying to get images from firebase firestore, while trying to get image download url there is this exception:我正在尝试从 firebase firestore 获取图像,同时尝试获取图像下载 url 有这个例外:

W/StorageUtil(10206): no auth token for request W/StorageUtil(10206):请求没有授权令牌

(similar questions with this error not solve the problem) (有此错误的类似问题不能解决问题)

Although my security rules allow read and write I getting this error still.尽管我的安全规则允许读写,但我仍然收到此错误。

Any ideas what is the problem with this?有什么想法吗?

Code for getting image url:获取图像 url 的代码:

  static Future<dynamic> loadImage(BuildContext context, String image) async {
    return await FirebaseStorage.instance.ref().child(image).getDownloadURL();
  }

Calling this loadImage function:调用此 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;
   });
  }

Calling this getImage function:调用此 getImage function:

child: FutureBuilder(
future: getImage(context, "/images/test1.jpg"),
...
)

My firebase storage rules:我的firebase存储规则:

rules_version = '2';
service firebase.storage {
match /images/{imageId} {
  allow read,write;
}
}

Storage Rules ss:存储规则 ss:

在此处输入图像描述

My firebase store currently:我的firebase店铺目前: 目前我的 firebase 商店

  • Navigate to Firebase console导航到 Firebase 控制台

  • In Sidebar under Develop open Storage在开发开放存储下的侧边栏中

  • Open Rules tab replace the rule on your console with the rule below:打开规则选项卡将控制台上的规则替换为以下规则:

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

And Publish Done并发布完成

I fixed it by changing the rules.我通过更改规则来修复它。

Go to Firebase project>Storage>Rules. Go 到 Firebase 项目>存储>规则。

By default, you are not allowed to upload on Firebase so you have to change that.默认情况下,您不允许在 Firebase 上上传,因此您必须更改它。

  • Default rules默认规则
rules_version = '2';
service firebase.storage {
  match /b/{bucket}/o {
    match /{allPaths=**} {
      allow read, write: if false;
    }
  }
}

Change allow read, write: if false;更改allow read, write: if false; to allow read, write; allow read, write;

(2022): Recently, I solved with following the Firestore basic security rules (for authenticated user): (2022):最近,我通过遵循 Firestore 基本安全规则(针对经过身份验证的用户)解决了问题:

service firebase.storage {
  match /b/{bucket}/o {
    match /{allPaths=**} {
      allow read, write: if request.auth != null;
    }
  }
}

You can see this in their website: https://firebase.google.com/docs/rules/basics?authuser=1#cloud-storage_1你可以在他们的网站上看到这个: https://firebase.google.com/docs/rules/basics?authuser=1#cloud-storage_1

I do not suggest that using allow read, write;我不建议使用 allow read, write; directly.直接地。 If your application has a authentication, then you need to check if auth is null or not.如果您的应用程序有身份验证,那么您需要检查 auth 是否为 null。

Go to Project Settings -> App Check -> Products Change the Storage from Enforce -> Unenforced Go 到 Project Settings -> App Check -> Products Change the Storage from Enforce -> Unenforced1

This works for me by changing the rules in firebase.通过更改 firebase 中的规则,这对我有用。

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 未处理的异常:[firebase_storage/unauthorized] 用户无权执行所需的操作 - Unhandled Exception: [firebase_storage/unauthorized] User is not authorized to perform the desired action firebase_storage/object-not-found 在所需的引用中不存在 object - firebase_storage/object-not-found No object exists at the desired reference firebase_storage object-not-found 没有 object 存在于所需的引用 flutter - firebase_storage object-not-found No object exists at the desired reference flutter Firestore 安全规则拒绝对 firebase-storage 进行读/写 - Firestore Security Rule denying read/write on firebase-storage Firebase存储:如果唯一的安全规则是“ auth!= null”,经过身份验证的恶意用户是否可以将大量文件写入Firebase Storage? - Firebase Storage: Can a malicious, authenticated user write a massive file to Firebase Storage if the only security rule is “auth != null”? Flutter: Upload Image Unhandled Exception: PlatformException(firebase_storage, The storage Uri cannot contain a path element., {}, null) - Flutter: Upload Image Unhandled Exception: PlatformException(firebase_storage, The storage Uri cannot contain a path element., {}, null) firebase_storage/unauthenticated 用户未经身份验证。 即使在发布版本中验证并重试错误 - firebase_storage/unauthenticated User is unauthenticated. Authenticate and try again error even in the release build Flutter&Firebase-与firebase_auth一起使用firebase_storage - Flutter & Firebase - using firebase_storage along with firebase_auth 我的 FirebaseStorage 方法未在 Flutter 中运行。 在 `firebase_storage: ^4.0.0` 之后 - My FirebaseStorage method isn't Running in Flutter. After the `firebase_storage: ^4.0.0` Firebase存储规则“未经授权” - Firebase storage rules “unauthorized”
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM