我正在尝试使用AWS S3 Direct和Angular 7上传多个文件。我需要显示进度条,但还需要等待一个周期结束才能继续执行功能:
组件:
async upload() {
for (const file of this.files) {
const data = await this.fileService.saveOnDB(file, this.id,
this.fileFG.controls['comment'].value, this.fileFGFG.controls['typeDoc'].value, file.size).toPromise();
if (data !== 'success') {
this.uploadComplete = false;
this.failFileNames += file.name + ', ';
} else {
await this.fileService.uploadFiles(file).subscribe(
myObserver => {
this.progressBar(myObserver);
this.myProgress = Math.floor(this.loadedTotal / this.granTotal * 100);
});
}
}
if (this.uploadComplete) {
this.activeModal.close(1);
Swal.fire('Complete', '', 'success');
} else {
Swal.fire('Not Complete', '', 'warning');
}
}
服务:
uploadFiles(file: File) {
const response = new Observable(observer => {
const params = {
...
};
bucket.upload(params, function (err, data) {
if (err) {
observer.error(err);
observer.complete();
} else {
observer.complete();
}
}).on('httpUploadProgress', event => {
observer.next(event);
}).send((err, data) => {
if (err != null) {
observer.error(err);
observer.complete();
}
});
});
return response;
}
在整个周期结束后,我需要继续使用该函数,具体是对以下调用:a。等待this.fileService.uploadFiles(file).subscribe(...。 >
有什么主意吗?