Friday, February 23, 2024
 Popular · Latest · Hot · Upcoming
90
rated 0 times [  94] [ 4]  / answers: 1 / hits: 38011  / 8 Years ago, tue, july 19, 2016, 12:00:00

I'm attempting to display an image from firebase into html img tags, but it fails to retrieve the image.



Javascript code:



var storageRef = firebase.storage().ref();
var spaceRef = storageRef.child('images/photo_1.png');
var path = spaceRef.fullPath;
var gsReference = storage.refFromURL('gs://test.appspot.com')

storageRef.child('images/photo_1.png').getDownloadURL().then(function(url) {
var test = url;
}).catch(function(error) {

});


html code:



<img src=test height=125 width=50/>

More From » html

 Answers
130

Once you have the test variable, you need to set the image's src to it using a script.



Something like this:





//var storage    = firebase.storage();
//var storageRef = storage.ref();
//var spaceRef = storageRef.child('images/photo_1.png');
//
//storageRef.child('images/photo_1.png').getDownloadURL().then(function(url) {
//
//
// var test = url;
// add this line here:
// document.querySelector('img').src = test;
//
//}).catch(function(error) {
//
//});
//
var test = 'firebase_url';

document.querySelector('img').src = test;

<img height=125 width=50/>




[#61320] Friday, July 15, 2016, 8 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
xiomara

Total Points: 378
Total Questions: 90
Total Answers: 104

Location: Guernsey
Member since Thu, Oct 7, 2021
2 Years ago
;