Reputation: 10930
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.
Upvotes: 9
Views: 9238
Reputation: 1549
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();
Upvotes: 0
Reputation: 3314
@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);
});
Upvotes: 1
Reputation: 10930
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()
.
Upvotes: 13