我正在将图像上传到Firebase,然后在上传完成后尝试检索URL,但出现此错误。
[Error] Error uploading image: – TypeError: undefined is not an object (evaluating 'snapshot.storageRef.getDownloadURL') — speakers.js:150
TypeError: undefined is not an object (evaluating 'snapshot.storageRef.getDownloadURL') — speakers.js:150
(anonymous function) (speakers.js:161)
promiseReactionJob
图片上传得很好,但是我没有URL。
var storageRef = firebase.storage().ref();
function uploadPhoto() {
if (selectedFile != null) {
var filePath = "Speaker Images/" + selectedFile.name + Date.now();
var upload = storageRef.child(filePath).put(selectedFile).then(function(snapshot) {
snapshot.storageRef.getDownloadURL().then(function(downloadUrl) {
console.log(downloadUrl);
uploadImageUrl = downloadUrl;
if (docId != null) {
updateSpeaker();
} else {
createNewSpeaker();
}
});
})
.catch(function(error) {
console.error("Error uploading image: ", error);
});
} else {
if (docId != null) {
updateSpeaker();
} else {
createNewSpeaker();
}
}
}
快照似乎很好。
[Log] Ee {bytesTransferred: 30255, totalBytes: 30255, state: "success", metadata: Object, task: e, …} (speakers.js, line 150)
答案 0 :(得分:2)
snapshot
变量的类型为UploadTaskSnapshot
,没有子变量storageRef
。您可能正在寻找snapshot.ref
:
snapshot.ref.getDownloadURL().then(function(downloadUrl) {
...