I'm creating a custom file up-loader for my project. I want to add "cancel file upload feature" also. Assume that I've already dragged and dropped some 4 or 5 file into the component. this files are stored in file
variable. When I click on "Upload" button from the UI following method will be called:
uploadFiles() {
const formData = new FormData();
formData.append('excel', this.file);
const headers = new HttpHeaders({
'x-request-id': 'file_upload_' + new Date().getTime(),
});
this.http
.post('http://localhost:8090/service/fileprocess/upload', formData, {
headers: headers,
responseType: 'json',
})
.pipe(catchError((err) => this.handleError(err)))
.subscribe((res: any) => {
// show success message to the user
});
}
Let's say I pressed the upload button but there is one file which is taking longer than expected. Then the user should be able to cancel that particular upload by clicking on its respective ban icon. This is my template:
<div class="row mt-1" *ngFor="let item of files; let indexOfelement=index;">
<div class="col-lg-1">
<p-progressSpinner *ngIf="fileUploading"></p-progressSpinner>
</div>
<div class="col-lg-3">
{{ item.relativePath }}
</div>
<div class="col-lg-6">
<p-progressBar *ngIf="fileFound" [value]="variable"></p-progressBar>
</div>
<div class="col-lg-2 text-end">
<i class="fa fa-ban" *ngIf="fileUploading" (click)="stopThisUpload(indexOfelement)"></i>
</div>
</div>
Can someone please guide me on this.