将Firebase存储文件的URL放入变量中



我正试图将图像的URL放入一个变量中,以便将图像中的URL记录到控制台。我不知道为什么,但每次我尝试这样做时,它都不会记录任何内容(也不会出错(。这就是我现在尝试的方式:

}, function() {
// The file is done uploading to Firebase Storage
let url = uploadTask.snapshot.downloadURL;
console.log(url)
}

我真的不知道我做错了什么,我知道这可能不是最难弄清楚的事情,但我真的找不到。有人能帮我吗?

您可以访问downloadURL,如:

task.on('state_changed', function(snapshot){
//....
}, function(error) {
// Handle unsuccessful uploads
}, function() {
// Handle successful uploads on complete
task.snapshot.ref.getDownloadURL().then(function(downloadURL) {
console.log('File available at', downloadURL);
});
});

最新更新