我正在将图像上传到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)
snapshot
变量是UploadTaskSnapshot
类型,没有storageRef
孩子。你可能正在寻找snapshot.ref
:
snapshot.ref.getDownloadURL().then(function(downloadUrl) {
...