skip to Main Content

I created this piece of code as a rule too limit number of items stored there, but I still can add as many new images, as I want.

     match /images/logo/{userId}/{imageId} {
      allow write: if request.resource.size < 1 * 1024 * 1024
                   && request.resource.contentType.matches('image/.*')
        &&  list(/images/logo/{userId}).size() < 1;
}

2

Answers


  1. It’s not possible to limit the number of objects in a Cloud Storage bucket using Firebase security rules. There is no function list() available in security rules.

    You’re probably better off recording the count of objects in a database and use that in conjunction with a Cloud Functions trigger to determine if an object should be allowed to remain after uploading.

    Login or Signup to reply.
  2. Let the client upload the logo image with the same filename, then there will be only one, even without rules.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search