仅 png 图像 firestore 的存储规则?

storage rules for only png images firestore?

我在存储规则中有以下代码,但我无法使其正常工作,我需要防止将 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.contentType.matches('image/.png'); // only PNG !!

尝试使用 .png 或 .PNG。它检查文件名是否以 .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 !!