【发布时间】:2018-11-18 08:56:06
【问题描述】:
我几天来一直在努力让 Firebase 在元数据中返回 downloadURL。所有人都认为它应该在那里,因为元数据包括 fullPath 和其他信息,但不包括 downloadURL。
addItem(
itemName: string,
eventId: string,
itemPicture: string = null
): PromiseLike<any> {
return this.activityListRef
.child(`${eventId}/itemList`)
.push({ itemName })
.then(newItem => {
this.activityListRef.child(eventId).transaction(event => {
return event;
});
if (itemPicture != null) {
return firebase
.storage()
.ref(`/item/${newItem.key}/profilePicture.png`)
.putString(itemPicture, 'base64', { contentType: 'image/png' })
.then(savedPicture => {
console.log(savedPicture.metadata);
this.activityListRef
.child(`${eventId}/itemList/${newItem.key}/profilePicture`)
.set(savedPicture.downloadURL);
});
}
});
}
如果我在控制台中记录,我可以看到除了 downloadURL 之外的所有内容
我也尝试过改变 .set(savedPicture.downloadURL); 到 .set(savedPicture.metadata.downloadURLS[0]);
但在任何响应参数中仍然没有 downloadURL 项。
有什么想法吗?
【问题讨论】:
-
在最新的 Cloud Storage for Firebase SDK 中,下载网址不再位于元数据中。相反,您需要在存储参考上调用
getDownloadUrl()以获取它,如 MuruGan 的答案所示。 -
谢谢弗兰克,这绝对是问题所在。我现在就拍。
标签: javascript firebase ionic-framework ionic3 firebase-storage