我试图将Promise返回值赋值给一个变量,但是它并没有被赋值。当我用console.log(this.imageref1)打印时,仍然得到空字符串。 这里的目标是获取上传照片到Firebase后返回的data.downloadURL。我需要downloadedURL来存储图像路径以在我的数据库中使用。我被卡在这里了,我的数据库获得了空的downloadURL数据。
post_news(form: NgForm){
this.title = form.value.title;
this.content = form.value.content;
this.category = form.value.category;
console.log(this.capturedimage1);
if(this.capturedimage1 !== ''){
//console.log('captured image is not empty');
let storageRef = firebase.storage().ref();
const filename = Math.floor(Date.now() / 1000);
const imageRef = storageRef.child(`images/${filename}.jpg`);
let uploaded_file_path = `images/${filename}.jpg`;
imageRef.putString(this.capturedimage1, firebase.storage.StringFormat.DATA_URL).then(data=>{
this.imageref1 = data.downloadURL;
});
}
}