【问题标题】:Firebase Storage getDownloadUrl() "is not a function"Firebase 存储 getDownloadUrl()“不是函数”
【发布时间】:2018-07-18 12:15:24
【问题描述】:
let storage = firebase.storage();
let storageRef = storage.ref("EnglishVideos/" + movieTitle + "/" + movieTitle + "_full.mp4");
    console.log(storageRef); // looks OK, no error messages

上述代码有效,从 Firebase 存储返回的对象位置正确,没有错误消息。

但是getDownloadUrl() 不起作用:

let myURL = storageRef.getDownloadUrl();
console.log(myURL); // TypeError: storageRef.getDownloadUrl is not a function

错误是TypeError: storageRef.getDownloadUrl is not a function。这似乎是一个原型链错误。我正在使用 AngularJS,也许我没有在我的控制器中注入必要的依赖项?我将$firebaseStorage 注入控制器,但没有帮助。我从这个控制器调用 Firebase 实时数据库工作正常。

【问题讨论】:

    标签: javascript angularjs firebase firebase-storage


    【解决方案1】:

    这是getDownloadURL,而不是getDownloadUrl。大写。我的工作代码是

    var storageRef = firebase.storage().ref("EnglishVideos/" + movieTitle + "/" + movieTitle + "_full.mp4");
      storageRef.getDownloadURL().then(function(url) {
        console.log(url);
      });
    

    official”版本是

    var storageRef = firebase.storage.ref("folderName/file.jpg");
    storageRef.getDownloadURL().then(function(url) {
      console.log(url);
    });
    

    请注意,在storage 之后我需要一个(),即storage()

    【讨论】:

    • 这也适用于我,谢谢。但是,如果我在构造函数(--> constructor(public storage: AngularFireStorage) { })中初始化存储,我不能在 this.storage.getDownloadURL() 之后链接 .then() 但在 this.storage.upload 之后(x, y).then() 没问题?
    • 我在下面为您的“then(...)”问题编写了解决方案
    【解决方案2】:

    @Thomas David Kehoe 的解决方案让我快到了。

    我仍然收到错误:

    ERROR TypeError: storageRef.getDownloadURL(...).then 不是函数

    这是我的解决方案:

    import { Observable } from 'rxjs';
    

    然后在我的函数内部:

    var storageRef = this.storage.ref('myFolder/myFile.jpg');
    storageRef.getDownloadURL().toPromise().then(function (url) {
        console.log(url);
    });
    

    【讨论】:

      【解决方案3】:

      就我而言,我试图在上传任务上调用getDownloadURL();,即

      var upload=storage.child(`Testing/abc.png`).put(chosenFile);
      //.....
      //.....
      upload.getDownloadURL();
       
      

      解决了

        var ImgUploadRef=storage.child(`Testing/abc.png`);
        var upload = ImgUploadRef.put(chosenFile);
         //....
         //....
         ImgUploadRef.getDownloadURL();
      

      【讨论】:

        猜你喜欢
        • 2020-04-02
        • 2021-12-18
        • 2021-04-06
        • 1970-01-01
        • 2018-10-02
        • 2021-12-20
        • 2020-07-19
        • 2021-12-26
        • 2021-01-29
        相关资源
        最近更新 更多