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 !!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 !!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With