📜  使用 Angular 上传文件 - Javascript 代码示例

📅  最后修改于: 2022-03-11 15:01:22.698000             🧑  作者: Mango

代码示例1
fileChange(element) {
  this.uploadedFiles = element.target.files;
}

upload() {
  let formData = new FormData();
  for (var i = 0; i < this.uploadedFiles.length; i++) {
    formData.append("uploads[]", this.uploadedFiles[i], this.uploadedFiles[i].name);
  }
  this.http.post('/api/upload', formData)
    .subscribe((response) => {
    console.log('response received is ', response);
  })
}