在html img标签中显示来自firebase存储的图片 [英] Display images from firebase storage in html img tags
本文介绍了在html img标签中显示来自firebase存储的图片的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我试图从firebase显示一个图片到html img
标签,但它无法检索图片。
Javascript代码:
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(函数(url){
var test = url;
})。catch(function(error){
});
html代码:
< img src =testheight =125width =50/>
解决方案
一旦您完成测试
变量,您需要使用脚本将图像的src设置为它。
类似于:
// var storage = firebase.storage(); // var storageRef = storage.ref(); // var spaceRef = storageRef.child('images / photo_1.png'); //// storageRef。 child('images / photo_1.png')。getDownloadURL()。然后(function(url){////// var test = url; //在这里添加这行:// document.querySelector('img') .src = test; ////})。catch(function(error){////}); // var test ='firebase_url'; document.querySelector('img')。src = test; code>
< img height =125width =50/ >
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"/>
解决方案
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"/>
这篇关于在html img标签中显示来自firebase存储的图片的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文