File Upload with Angular2 to REST API

后端 未结 9 1065
萌比男神i
萌比男神i 2020-11-27 10:14

Actually, I\'m working on a Spring REST API with an interface coded in Angular 2.

My problem is I can\'t upload a file with Angular 2.

My Webresources in jav

9条回答
  •  北海茫月
    2020-11-27 11:14

    fileUpload() {
      const formData = new FormData();
    
      const files = this.filesToUpload;
      for (let i = 0; i < files.length; i++) {
        formData.append('file', files.item(i));
        formData.append('Content-Type', 'application/json');
        formData.append('Accept', `application/json`);
      }
    
    
      this.http.post('http://localhost:8080/UploadFile', formData).subscribe(response => console.log(response));
    }
    

    Then:

提交回复
热议问题