Reputation: 2284
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 !!
Upvotes: 4
Views: 768
Reputation: 860
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 !!
Upvotes: 5