Firebase storage rules apply to delete rules

These are my rules applied to the img file:

match /img { match /{fileId} { allow read, write: if request.resource.contentType.matches('image/jpeg') || request.resource.contentType.matches('image/png') || request.resource.contentType.matches('image/gif') && request.resource.size < 2 * 1024 * 1024 } } } 

The problem is that these rules also apply to delete (), since it is a write method, so it always returns a permission error. I could not find anything in the documentation about this. How to cancel POST / PUT and DELETE rules?

+5
source share
1 answer

Found a solution myself. By allowing the rule to apply when there is no resource sent at all (delete), it also gets write permission. The rest of the create / update code is sent to the OR expression.

 match /img { match /{fileId} { allow read, write: if request.resource == null || (request.resource.contentType.matches('image/jpeg') || request.resource.contentType.matches('image/png') || request.resource.contentType.matches('image/gif') && request.resource.size < 2 * 1024 * 1024) } } 
+13
source

All Articles