Firestore:使用request.resource.size规则返回FirebaseError:缺少权限或权限不足 [英] Firestore: Usage of request.resource.size rule returns FirebaseError: Missing or insufficient permissions

查看:38
本文介绍了Firestore:使用request.resource.size规则返回FirebaseError:缺少权限或权限不足的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试建立一个Firestore安全规则以限制传入数据的大小.

I am trying to set up a firestore security rule to restrict the size of incoming data.

service cloud.firestore {
  match /databases/{database}/documents {
  match /events/{eventId}{
        allow read: if request.auth.uid != null;     
        allow write: if request.auth.uid != null
            && request.resource.size < 1*1024*1024;
      }
  }
}

以上安全规则返回错误

FirebaseError:缺少权限或权限不足.

FirebaseError: Missing or insufficient permissions.

如何验证传入数据的大小而不会出现错误?

How do I validate the size of the incoming data without the error?

Firestore结构

firestore_db.collection('/events').add({
            createdAt: firebase.firestore.Timestamp.now().toMillis(),
            uid: currentUserId,
            actionData: JSON.stringify((action)
            )
          });  

示例代码

推荐答案

在Cloud Firestore中, Resource 输入存储,它确实具有这种属性.

In Cloud Firestore the Resource type doesn't have a size property. You're probably mistaking it with the Resource type in Storage, which does have such a property.

还请注意,如果资源大于1MB(这是最大文档大小),Firestore将始终拒绝写入.

Also note that Firestore would always reject writes where the resource becomes larger than 1MB as that is the maximum document size.

这篇关于Firestore:使用request.resource.size规则返回FirebaseError:缺少权限或权限不足的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆