Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

storage rules for only png images firestore?

I have the following code in storage rules , but I cannot get it to work right, I need to prevent storing items other than pngs in to storage ? , but it is erroring out.

     // Add to storage     
      allow write:  
      if request.auth != null  // Authorized
      && request.auth.uid == userId  // Owner
      && request.resource.size < 1 * 1024 * 1024 // Uploaded item must be less than 1mb !
      && request.resource.contentType.matches('image/.*'); // only image !!
    //  && request.resource.contentType.matches('image/.png'); // only PNG !!
like image 875
Richardson Avatar asked Sep 07 '25 08:09

Richardson


1 Answers

try with .png or .PNG. It checks if the filename ends with .png

// Add to storage     
      allow write:  
      if request.auth != null  // Authorized
      && request.auth.uid == userId  // Owner
      && request.resource.size < 1 * 1024 * 1024 // Uploaded item must be less than 1mb !
      && request.resource.contentType.matches('image/.*'); // only image !!
      && request.resource.name.matches(".*\\.png"); // only PNG !!
like image 140
Hans Murangaza DRCongo Avatar answered Sep 10 '25 03:09

Hans Murangaza DRCongo