有没有一种简单的方法来获取上传到 Firebase 的文件的下载 URL?
(我尝试过使用我的上传函数返回的快照,但找不到任何东西......)
fileref.put(file).then(function(snapshot){
self.addEntry(snapshot);
/// return snapshot.url???
});
Yamil 引用的文档 -Firebase javascript SDK 文件上传- 建议使用快照ref
属性来调用getDownloadURL
方法,它返回一个包含下载链接的承诺:
使用您的代码作为起点:
fileref.put(file)
.then(snapshot => {
return snapshot.ref.getDownloadURL(); // Will return a promise with the download link
})
.then(downloadURL => {
console.log(`Successfully uploaded file and got download link - ${downloadURL}`);
return downloadURL;
})
.catch(error => {
// Use to signal error if something goes wrong.
console.log(`Failed to upload file and get link - ${error}`);
});
我知道这似乎是不必要的努力,并且您应该能够通过快照的属性获取链接,但这是 Firebase 团队的建议 - 他们可能有充分的理由这样做。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)