Angularfire2:如何从 Firebase 存储中检索文件内容

Angularfire2: how to retrieve file content from Firebase storage

我正在使用 Angulfire2 开发 Ionic 应用程序。

我已成功将文件上传到 Firebase。

我找到了方法 getDownloadURL 来检索文件 URL 并且在 HTML 页中显示它工作正常。

但是我找不到下载文件内容的方法。我尝试执行这样的 http 请求:

let headers = new HttpHeaders({ "Content-Type": "image/png" });
let imageGet = this.http.get(firestorageImageURI, { headers: headers }).subscribe((response) => {
    debugger;
});

但是我在控制台中遇到 CORS 错误:

Access to XMLHttpRequest at 'https://firebasestorage.googleapis.com/v0/b/xxxx.appspot.com/o/edls%2Fb2478a2b-48eb-4056-94c8-e83d858cd519%2Fb2478a2b-48eb-4056-94c8-e83d858cd519_b_1603046492694.png?alt=media&token=8ce76185-dd05-451e-919e-49f695145237' from origin 'http://localhost:8101' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.

我还配置了 CORS 以允许所有来源,如下所述: https://firebase.google.com/docs/storage/web/download-files

但是并没有改错。

我还将存储规则更改为:

rules_version = '2'; 
service firebase.storage {   
  match /b/{bucket}/o {
     match /{allPaths=**} {
          allow read, write: if true;
     }   
  } 
}

有人知道如何使用 angularfire2 从 Firebase 存储下载文件吗?

提前致谢

发现问题,headers 不应发送查询。