在我的Angular应用程序中,我正在尝试检索保存在Firebase存储中的文件。
为此,我编写了以下代码:
这段代码遵循 Firebase 的文档(https://firebase.google.com/docs/storage/web/download-files),但它却无法工作。
具体而言,程序在以下行停滞:
然而,这会出现以下错误信息:
为此,我编写了以下代码:
var storage = firebase.storage();
var fileRef = storage.ref(`${this.idOfCurrentUser}/personalData.card`);
var blob = null;
console.log("THIS LINE DOES GET PRINTED");
fileRef.getDownloadURL().then(function(url) {
console.log("THIS LINE NEVER GETS PRINTED");
var xhr = new XMLHttpRequest();
xhr.responseType = 'blob';
xhr.onload = function(event) {
blob = xhr.response;
};
xhr.open('GET', url);
xhr.send();
}).then(function() {
//some more code
}).catch(function(error) {
console.log(error);
});
这段代码遵循 Firebase 的文档(https://firebase.google.com/docs/storage/web/download-files),但它却无法工作。
具体而言,程序在以下行停滞:
fileRef.getDownloadURL().then(function(url) {
控制台没有错误信息,但是轮子一直在转动,整个应用程序变得无法使用。
请问有人知道从Firebase Storage检索文件的有效方法吗?
更新:
根据Joseph Webber的建议,我将代码的前几行更改为以下内容:
var storage = firebase.storage();
var id = this.idOfCurrentUser;
var fileRef = storage.ref(`${id}/personalData.card`);
然而,问题依旧存在。
更新2:
根据Joseph Webber的另一个建议,我也尝试了以下操作:
var fileRef = storage.child(`${id}/personalData.card`);
然而,这会出现以下错误信息:
"Property 'child' does not exist on type 'Storage'"
UPDATE3:
also tried this:
var fileRef = storage.ref(this.idOfCurrentUser + "/personalData.card");
...也没有什么区别
附:存储规则如下:
storage.ref(this.idOfCurrentUser + '/personalData.card')
你确定路径正确(id
与uid
)并且文件存在吗? - Joseph Webber