uploadFileOnServer() {
const myData = new FormData();
let uuid = this.generateUUID();
for (let i=0; i<this.file.length; i++) {
myData.append('file', this.file[i]);
myData.append('uuid', uuid);
const options = {headers: new HttpHeaders()};
this.http.post(this.apiUrl, myData, options).subscribe(
data => {
console.log('Succes');
},
err => {
console.log('Something went wrong!');
}
);
}
}
有这样的代码,但我认为在循环中执行post请求很糟糕,如何在不使用循环的情况下发送文件。 Angular5