Answer the question
In order to leave comments, you need to log in
How to monitor file upload status to server in angular 5?
Guys, hello everyone.
Tell me how to upload several files to the server with tracking of their status (completion) of the download
created such a function
public sendFiles(data) {
const headers = new HttpHeaders().set(
'Authorization',
'Bearer ?????????????????????????????'
);
const req = new HttpRequest(
'POST',
'http://localhost:8081/upload/files',
data,
{ reportProgress: true, headers, responseType: 'text' }
);
return this.httpClient.request(req);
}
public changeinput(event) {
let chosenFiles = event.target.files || event.srcElement.files;
const error = this.validateFiles(chosenFiles);
if (error.length) {
alert(error);
let btn: HTMLInputElement = document.getElementById(
'file-uploads'
) as HTMLInputElement;
btn.value = null;
} else {
Array.prototype.push.apply(this.transmittedFiles, chosenFiles);
const formData = new FormData();
Array.prototype.forEach.call(this.transmittedFiles, (file, index) => {
console.log(file);
formData.append(`files`, file);
});
this.dataExchangeService
.sendFiles(formData)
.subscribe(event => console.log(event));
}
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question