2
I am sending a file selected by the user in the browser through the tag "input" to the Asp net core and would like to display the progress of the upload.
I currently only get the Enum "Httpeventtype" result 2 which means "The Response status code and headers Were Received". It does not fall under either of the two conditions expected in this code. You should receive callbacks with type 1 "Uploadprogress" result in order to display the progress on the screen.
vine angular io.
this.meuServico.saveFile(this.selectedFile).subscribe(
(result) => {
let event: any = result;
if (event.type === HttpEventType.UploadProgress) {
// This is an upload progress event. Compute and show the % done:
const percentDone = Math.round(100 * event.loaded / event.total);
console.log(`File is ${percentDone}% uploaded.`);
}
else if (event instanceof HttpResponse) {
console.log('File is completely uploaded!');
}
},
(error) => {
console.log('upload error', error);
}
);
}
my service that creates the request:
public saveFile(file) {
let url = 'minha url de backend asp net core 2.2 / uploadFile';
let formData: FormData = new FormData();
formData.append('uploadFile', file, file.name);
let headers = {};
headers['Content-Disposition'] = 'multipart/form-data';
headers['Accept'] = 'application/json';
let options: any = {
reportProgress: true,
observe: 'events',
headers: headers
};
return this.api.post(url, formData, options);
}