1
我發送給後端文件,這是下面的代碼上傳:Recieving上傳從客戶端文件,休息
export class FileUploadComponent {
@Input() multiple: boolean = false;
@ViewChild('fileInput') inputEl: ElementRef;
constructor(private http: Http) {}
upload() {
let inputEl: HTMLInputElement = this.inputEl.nativeElement;
let fileCount: number = inputEl.files.length;
let formData = new FormData();
if (fileCount > 0) { // a file was selected
for (let i = 0; i < fileCount; i++) {
formData.append('file[]', inputEl.files.item(i));
}
this.http
.post('http://localhost:8080/upload', formData).toPromise().then(() => console.log('success')).catch(() => console.log('error'));
}
}
}
現在
上,我想通過控制器來接受她的backendside,但我不知道如何映射文件屬性,以下給出null:
public @ResponseBody String handleFileUpload(@RequestBody MultipartFile file)
[AngularJS FORMDATA文件上傳數組(可能的重複https://stackoverflow.com/問題/ 33920248/angularjs-FORMDATA文件陣列上傳) –