【发布时间】:2017-11-28 21:35:07
【问题描述】:
我正在尝试将承诺返回值分配给一个变量,但它没有分配。当我 console.log(this.imageref1) 时,我仍然得到空字符串。 这里的目标是获取将照片上传到 Firebase 后返回的 data.downloadURL。我需要下载的URL。将其存储在我的数据库中作为图像路径。我被困在这里,我的数据库为 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;
});
}
}
【问题讨论】:
标签: javascript angular typescript angular-promise ionic3