【发布时间】:2019-06-14 10:07:36
【问题描述】:
我正在尝试构建此功能以在我的应用程序的个人资料页面上上传个人资料图片,问题是由于图片上传功能,我得到了ZoneAwarePromise。我尝试了很多不同的方法,但无法改变结果。
有人可以帮我吗?我做错了什么?
uploadService.ts
pictureUpload(file: any, uid: string) {
return this.afUpload.upload('profile/' + uid, file);
}
profile.component.ts
onCreateUser() {
const picture = this.uploadService.pictureUpload(this.fileInput.nativeElement.files['0'], currentUserID).then(
async (data) => {
try {
return data.ref.getDownloadURL();
} catch {
console.error();
} finally {
const email = this.userProfileForm.value.email;
const firstName = this.userProfileForm.value.firstName;
const lastName = this.userProfileForm.value.lastName;
const userObj = {
'uid': currentUserID,
'email': email,
'firstName': firstName,
'lastName': lastName,
'picture': picture
};
console.log('the object is');
console.log(userObj);
if (this.editMode) {
return this.db.object('profile/' + currentUserID).update(userObj).then(
() => {
return this.presentToaster('Dados atualizados');
},
(e) => {
this.presentToaster(e);
console.error(e);
}
);
} else {
const load = await this.loadCtrl.create({
message: 'Criando Usuario'
});
await load.present();
return this.db.object('profile/' + currentUserID).set(userObj).then(
() => {
load.dismiss();
return this.navCtrl.navigateRoot('news');
},
(error) => {
load.dismiss();
this.presentToaster(error);
console.error(error);
}
);
}
}
},
(error) => {
console.error(error);
}
);
}
【问题讨论】:
标签: angular firebase ionic-framework angularfire2