【发布时间】:2018-03-11 00:08:02
【问题描述】:
我正在为应用程序使用 Firebase 存储,以便可以存储要在弹出窗口中显示的图像。现在我可以参考图像,但我无法使用getDownloadURL() 获取图像的URL。
我已经尝试了所有方法,但似乎无法获取 URL,并且只在控制台中出现错误提示 Error: Reference.push failed: the first argument contains undefined in property 'markers.imageURL.i'", AND " Failed to load resource: the server responded with a status of 404 (HTTP/2.0 404)
有人知道为什么吗?
这是我的代码的 sn-p。 imageFURLY 是不返回 URL 的。
document.getElementById('infowindowSubmit').addEventListener('click', function (event, imageFURL) {
// This function saves the newly created marker and the infowindow information when
//the 'Submit' button is clicked.
var fileInput = document.getElementById('fileInput');
var file = fileInput.files[0];
//Create storage ref
var storageRef = firebase.storage().ref('markerpics/' + file.name);
var task = storageRef.put(file);
console.log('storageRef ', storageRef)
imageFURL = storageRef;
console.log('imageFURL ', imageFURL);
//Upload file
imageFURLY = imageFURL.getDownloadURL();
console.log('imageFURLY ', imageFURLY);
//Variables that store data inputted in infowindow
var postName = document.getElementById('formName');
var postNameF = postName.value;
var postMessage = document.getElementById('formMessage');
var postMessageF = postMessage.value;
var postImageRef = imageFURLY;
console.log('postImageRef - URL: ', postImageRef);
var latitude = location.lat(location);
var longitude = location.lng(location);
//Closes markers open infowindow
largeInfowindow.close(map, marker);
//Sets markers infowindow to NEW content
console.log('Setting infowindow content!! ');
largeInfowindow.setContent('<div>' + '<div>Name: ' + postNameF + '</div><br>' + '<div>Message: ' + postMessageF + '</div><br>' + '<div>Image: ' + '</div>' + '<img style="height: 100px; width: 100px;" src="' + postImageRef + '" alt="Mountain View">' + '<br>' + '</div>');
console.log('Set infowindow content!! ');
largeInfowindow.open(map, marker);
// Make sure the marker property is cleared if the infowindow is closed.
largeInfowindow.addListener('closeclick', function () {
largeInfowindow.marker = null;
});
【问题讨论】:
-
变量
file是否包含您所期望的内容? -
是的。代码按照我的预期执行,直到出现 'imageFURLY = imageFURL.getDownloadURL(); console.log('imageFURLY', imageFURLY);' File 给了我我所期望的,甚至 imageFURL 也可以。但 imageFURLY 没有。我认为这与 JS 一次运行代码有关,但老实说我不确定
标签: javascript angularjs firebase url storage