我正在尝试从Firebase获取图像的downloadUrl,所有属性,例如'timeCreated','fullPath','contentType'均正常运行并正确推送!但我不知道为什么“ downloadUrl”不起作用!
captureAndUpload() {
this.dataProvider.captureImage().then(data => {
this.dataProvider.uploadImage(data).then(res => {
this.dataProvider.storeImageInformation(res.downloadURL);
});
});
}
数据提供者:
storeImageInformation(downloadURL)
{
this.db.list(`/profiles/${this.afAuth.auth.currentUser.uid}`).
push(downloadURL);
}
有什么想法吗?!
答案 0 :(得分:2)
THX Doug,您是对的。
正确的代码如下:
captureAndUpload() {
this.data.captureImage().then(data => {
let upload = this.data.uploadImage(data);
upload.then().then(res => {
this.data.storeImageInformation(res);
});
}
数据提供者:
uploadImage(image) {
let storageRef: AngularFireStorageReference;
let newName = `${new Date().getTime()}-${this.afAuth.auth.currentUser.uid}.png`;
storageRef = this.afStorage.ref(`/images/${this.afAuth.auth.currentUser.uid}/${newName}`);
return storageRef.putString(image, 'base64', { contentType: 'image/png'})
.snapshotChanges().toPromise().then(_ =>
{
return storageRef.getDownloadURL().toPromise().then(res => {
console.log('URL: ', res);
return res;
});
}
)
}
storeImageInformation(downloadURL) {
return this.db.object(`/images/${this.afAuth.auth.currentUser.uid}`).update({img: downloadURL}); }
答案 1 :(得分:1)
现在在上载的即时结果中不再可以访问下载URL。几个月前,对Firebase客户端SDK进行了此更改。
相反,您必须调用getDownloadURL(或该JavaScript函数的Angular绑定),以在完成上传后将URL作为第二个请求。