Reputation: 3310
According to the documentation I've read ref.getDownloadURL();
should return a link I could use in an img src.
Here is my code: This is how I fire up firebase:
this.storage = app.storage();
storageRef = img => this.storage.ref(img);
I then call it like so:
const householdPics = (data, props) => {
const ref = props.firebase.storageRef(`images/${data.profilePic}`);
const img = ref.getDownloadURL();
console.log(img);
}
data.profilePic is equal to something.jpg. I can confirm it's in storage in firebase in a directory called
images/
The error I get in my console is:
"Firebase Storage: Object 'images/NULL' does not exist."
From firebase I can copy the path: gs://urlstuff.com/images Then all my images are listed.
What am I doing wrong?
Upvotes: 0
Views: 114
Reputation: 262
To get result of async method, you have to use then
to get final url with access code attached to it.
ex.
storageRef
.getDownloadURL().then(url => { console.log(url) });
Here, your url will be printed at console.
Upvotes: 2
Reputation: 317372
Two things are wrong here.
First of all, the error message is suggesting that your value of data.profilePic
is null. That's not valid - be sure to validate your data.
Second of all, as you can see from the API documentation, getDownloadURL() doesn't return the URL directly. It's asynchronous and returns a promise that resolves when the URL is available. This means you have to await
it or use then
to capture its final value, after the async work is done.
Upvotes: 1