我正在使用firebase和angular。 我想用这个功能上传文件,它运行得很好但是当我想保存上传到变量 fileUrl
中的文件的URL时出错ERROR TypeError: Cannot set property 'fileUrl' of undefined
我认为这是解析 fileUrl 和 downloadURL
之间的问题fileUrl:string;
uploadFile(file: File) {
return new Promise(
(resolve, reject) => {
const almostUniqueFileName = Date.now().toString();
const upload = firebase.storage().ref().child('ProfileImage/' + almostUniqueFileName + "xx").put(file);
upload.on(firebase.storage.TaskEvent.STATE_CHANGED,
(snapshot) => {
console.log('Chargement…');
this.progress = (upload.snapshot.bytesTransferred / upload.snapshot.totalBytes) * 100;
},
(error) => {
console.log('Erreur de chargement ! : ' + error);
reject();
},
() => {
upload.snapshot.ref.getDownloadURL().then(function(downloadURL) {
console.log(downloadURL);
this.fileUrl = downloadURL;
console.log(this.fileUrl);
});
resolve(upload.snapshot.downloadURL);
}
);
}
);
}
请帮助我