我想显示上传的图片,但即使我登录也出现 403 错误。
上传工作正常,downloadURl 没问题。
而且我已经认证了(上传成功表明我已经登录了)
但我无法显示上传的图片。
storage.child(file_name).put(event_image).then(function(snapshot) {
console.log('Uploaded a blob or file!');
var img_src = snapshot.downloadURL;
$('img#uploaded').attr('src',img_src);
});
最佳答案
使用此链接:https://firebase.google.com/docs/storage/web/download-files#download_data_via_url
storageRef.child('images/stars.jpg').getDownloadURL().then(function(url) {
// `url` is the download URL for 'images/stars.jpg'
// This can be downloaded directly:
var xhr = new XMLHttpRequest();
xhr.responseType = 'blob';
xhr.onload = function(event) {
var blob = xhr.response;
};
xhr.open('GET', url);
xhr.send();
// Or inserted into an <img> element:
var img = document.getElementById('myimg');
img.src = url;
}).catch(function(error) {
// Handle any errors
});
关于image - 显示来自 Firebase 存储的图像时出现 404 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42303230/