ste*_*ess 5 firebase typescript firebase-storage angular
在我的Angular应用程序中,我正在尝试检索保存在firebase存储上的文件.
为此我写了以下代码:
    var storage = firebase.storage();
    var fileRef = storage.ref(`${this.idOfCurrentUser}/personalData.card`);
    var blob = null;
    console.log("THIS LINE DOES GET PRINTED");
    fileRef.getDownloadURL().then(function(url) {
        console.log("THIS LINE NEVER GETS PRINTED");
        var xhr = new XMLHttpRequest();
        xhr.responseType = 'blob';
        xhr.onload = function(event) {
            blob = xhr.response;  
        };
        xhr.open('GET', url);
        xhr.send();
    }).then(function() {
        //some more code
    }).catch(function(error) {
        console.log(error);
    });
Run Code Online (Sandbox Code Playgroud)
此代码遵循firebase文档(https://firebase.google.com/docs/storage/web/download-files)...但它不起作用.
具体来说,该程序在以下行停滞:
fileRef.getDownloadURL().then(function(url) {
Run Code Online (Sandbox Code Playgroud)
控制台中没有错误消息.但轮子永远转动,整个应用程序变得无法使用.
有人知道从Firebase存储中检索文件的工作方式吗?
更新:
根据Joseph Webber的建议,我将代码的第一行更改为以下内容:
    var storage = firebase.storage();
    var id = this.idOfCurrentUser;
    var fileRef = storage.ref(`${id}/personalData.card`);
Run Code Online (Sandbox Code Playgroud)
但是,问题保持完全相同.
UPDATE2:
根据Joseph Webber的另一个建议,我也尝试了以下方法:
var fileRef = storage.child(`${id}/personalData.card`);
Run Code Online (Sandbox Code Playgroud)
但是,这会给出以下错误消息:
"Property 'child' does not exist on type 'Storage'"
Run Code Online (Sandbox Code Playgroud)
UPDATE3:
还试过这个:
var fileRef = storage.ref(this.idOfCurrentUser + "/personalData.card");
Run Code Online (Sandbox Code Playgroud)
......也没有什么不同
PS:存储规则如下:
|   归档时间:  |  
           
  |  
        
|   查看次数:  |  
           824 次  |  
        
|   最近记录:  |