问题
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