[英]Firebase not returning downloadURL in metaData with typescript and Ionic3
我已经努力工作了好几天才能让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项。
有任何想法吗?
使用putString方法上传原始字符串后,请使用相同的ref并使用getDownloadUrl()方法获取如下所示的网址,
storage()
.ref(`/item/${newItem.key}/profilePicture.png`).getDownloadUrl() // which returns promise in turn returns the image url once it's available.
就您而言,您可以像下面这样
var storageRef = firebase.storage().ref(`/item/${newItem.key}/profilePicture.png`)
return storageRef.putString(itemPicture, 'base64', { contentType: 'image/png' })
.then(savedPicture => {
storageRef.getDownloadUrl()
.then(url =>{
this.activityListRef
.child(`${eventId}/itemList/${newItem.key}/profilePicture`)
.set(url);
});
});
希望这可以帮助
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.