You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Firebase Storage安全规则调用Firestore报错:无效函数名get

问题修复方案

错误的核心原因有两个:

  • Firebase Storage安全规则中,访问Firestore数据不能直接使用get()函数,必须通过firestore.get()明确指定Firestore服务的方法。
  • 函数调用时传递了多余的参数,函数定义未接收该参数会导致逻辑异常。

修正后的完整规则代码:

rules_version = '2';
service firebase.storage {
  match /b/{bucket}/o {
    
    match /orders/{orderId}/{folder}/{fileName} {
      function isUserAssociatedWithOrder() {
        return request.auth != null &&
          firestore.get(/databases/(default)/documents/ordersPublic/$(orderId)).data.customerUid == request.auth.uid
      }

      // Read and upload only if user is part of the order
      allow read, write: if isUserAssociatedWithOrder();

      // Explicitly disallow update/delete
      allow update, delete: if false;
    }
  }
}

关键修改点:

  1. 将get()替换为firestore.get():Storage规则环境下,必须通过firestore前缀来调用Firestore的读取方法,否则会被识别为无效函数。
  2. 移除函数调用时的orderId参数:match块中已捕获{orderId}变量,函数内部可直接访问,无需额外传递。

内容的提问来源于stack exchange,提问作者Jasperan

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.12 22:22:05