【问题标题】:Making firebase storage public for reading and writing on android公开firebase存储以在android上读写
【发布时间】:2016-12-04 08:33:14
【问题描述】:

我是 Firebase 存储的新手。谁能告诉我如何公开存储文件以供读写? firebase 提供的默认代码如下所示。我应该做哪些改变?

service firebase.storage {
  match /b/image-view-b1cf5.appspot.com/o {
    match /{allPaths=**} {
      allow read, write: if request.auth != null;
    }
  }
}

【问题讨论】:

    标签: android firebase firebase-realtime-database firebase-authentication firebase-security


    【解决方案1】:

    documentation 解释说,如果没有提供规则表达式,则规则的计算结果为 true:

    service firebase.storage {
      match /b/image-view-b1cf5.appspot.com/o {
        match /{allPaths=**} {
          // Allow access by all users
          allow read, write;
        }
      }
    }
    

    【讨论】:

    • 这并没有提醒我们我们的存储是公共的,就像在 firebase 数据库中那样。你确定这是公开的唯一方法吗?
    • @ahay:如果需要提醒,请在规则中添加评论。
    【解决方案2】:

    仅供参考:如果您想要公开只读。

    service firebase.storage {
      match /b/image-view-b1cf5.appspot.com/o {
        match /{allPaths=**} {
            allow read;
            allow write: if request.auth != null;
        }
      }
    } 
    

    【讨论】:

    • 好一个;找不到如何在他们的文档上设置 d/t 规则以进行读写。
    【解决方案3】:
    service firebase.storage {
      match /b/{bucket}/o {
        match /{allPaths=**} {
          allow read, write;
        }
      }
    } 
    

    【讨论】:

    • 这个答案有什么(除了糟糕的缩进)以前的答案没有?
    【解决方案4】:

    删除身份验证条件应该可以工作。

    【讨论】:

    • 这不是真的。
    • 如果你不改变自动生成的代码,它是公开的,可以通过它提供的链接访问。
    • 这不是真的。默认情况下它受到保护(仅限经过身份验证的用户)。查看文档:firebase.google.com/docs/storage/security
    • 这是我上面发布的文档的摘录:例如,默认的存储安全规则需要 Firebase 身份验证才能对所有文件执行任何读取或写入操作。
    • 我进行了从一组 android 设备到 windows pc 的跨平台数据传输。对于android设备,使用了身份验证,但对于pc版本,我没有使用身份验证,并且运行顺利。
    【解决方案5】:

    只是删除

    如果 request.auth != null;

    service firebase.storage {
      match /b/image-view-b1cf5.appspot.com/o {
        match /{allPaths=**} {
          // Allow access by all users
          allow read, write;
        }
      }
    }
    

    快乐编码

    【讨论】:

      【解决方案6】:
      // Anyone can read or write to the bucket, even non-users of your app.
      // Because it is shared with Google App Engine, this will also make
      // files uploaded via GAE public.
      service firebase.storage {
        match /b/{bucket}/o {
          match /{allPaths=**} {
            allow read, write;
          }
        }
      }
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2019-09-07
        • 2017-10-31
        • 2020-05-13
        • 2021-06-18
        • 1970-01-01
        • 1970-01-01
        • 2021-01-03
        • 1970-01-01
        相关资源
        最近更新 更多