Firestore: Usage of request.resource.size rule returns FirebaseError: Missing or insufficient permissions

无人久伴 提交于 2021-01-29 06:44:02

问题


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;
      }
  }
}

Above security rule returns an error

FirebaseError: Missing or insufficient permissions.

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

Firestore structure

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

Sample code


回答1:


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.

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



来源:https://stackoverflow.com/questions/55918923/firestore-usage-of-request-resource-size-rule-returns-firebaseerror-missing-or

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!