繁体   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)

我正在尝试从 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店铺目前: 目前我的 firebase 商店

  • 导航到 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 -> Unenforced1

通过更改 firebase 中的规则,这对我有用。

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

暂无
暂无

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM