最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Firebase Storage getDownloadUrl() "is not a function" - Stack Overflow

programmeradmin11浏览0评论
let storage = firebase.storage();
let storageRef = storage.ref("EnglishVideos/" + movieTitle + "/" + movieTitle + "_full.mp4");
    console.log(storageRef); // looks OK, no error messages

The above code works, the object returned from Firebase Storage has the correct location, no error messages.

But getDownloadUrl() doesn't work:

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

The error is TypeError: storageRef.getDownloadUrl is not a function. It seems like a prototype chain bug. I'm using AngularJS, maybe I didn't inject a necessary dependency into my controller? I injected $firebaseStorage into the controller but it didn't help. My calls to Firebase Realtime Database from this controller are working fine.

let storage = firebase.storage();
let storageRef = storage.ref("EnglishVideos/" + movieTitle + "/" + movieTitle + "_full.mp4");
    console.log(storageRef); // looks OK, no error messages

The above code works, the object returned from Firebase Storage has the correct location, no error messages.

But getDownloadUrl() doesn't work:

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

The error is TypeError: storageRef.getDownloadUrl is not a function. It seems like a prototype chain bug. I'm using AngularJS, maybe I didn't inject a necessary dependency into my controller? I injected $firebaseStorage into the controller but it didn't help. My calls to Firebase Realtime Database from this controller are working fine.

Share Improve this question edited Dec 29, 2019 at 8:21 georgeawg 49k13 gold badges77 silver badges98 bronze badges asked Feb 8, 2018 at 2:59 Thomas David KehoeThomas David Kehoe 10.9k18 gold badges75 silver badges122 bronze badges
Add a comment  | 

3 Answers 3

Reset to default 13

It's getDownloadURL, not getDownloadUrl. Capitalization. My working code is

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

The "official" version is

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

Note that I needed a () after storage, i.e., storage().

@Thomas David Kehoe's solution got me nearly there.

I was still getting the error:

ERROR TypeError: storageRef.getDownloadURL(...).then is not a function

Here's my solution:

import { Observable } from 'rxjs';

and then inside my function:

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

In my case, i was trying to call getDownloadURL(); on the upload task i.e

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

solved it by doing

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

评论列表(0)

  1. 暂无评论