Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Firebase Storage getDownloadUrl() "is not a function"

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.

like image 398
Thomas David Kehoe Avatar asked Feb 08 '18 02:02

Thomas David Kehoe


1 Answers

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().

like image 155
Thomas David Kehoe Avatar answered Oct 15 '22 18:10

Thomas David Kehoe