chrome 网络下出错
{ timeStamp: ......, status: 400
error: 'Bad Request',
message: 'Required request part 'file' is not present'
path: 'url as hosted on Tomcat'
}
Spring Boot Controller.java 文件
@PostMapping("/Post")
public ResponseEntity<String> handleFileUpload(@RequestParam("file")
MultipartFile file){ String Message=""; try .......(and so on)}
我的角度组件
<form [formGroup]="uploadForm" (ngSubmit) = "onSubmit()">
<input type="file" id="selectFile" formControlName="file1" name="selectFile"
(change)="fileEvent($event)"/>
<input type="submit" name="Submit"/>
</form>
组件.ts 文件
fileEvent(e) {
this.data = e.target.files[0];
}
omSubmit() {
let headers: any = new Headers();
headers.append('Content-type', 'undefined');
let formData = new FormData();
formData.append("selectFile", this.data);
const req5 = new HttpRequest('POST', 'url as hosted on TOMCAT', formData,
reportProgress: true,
responseType: 'text'
});
return this.httpClient.request(req5).subscribe(e => {(
console.log(e);
)}
}
我哪里出错了?
This:
formData.append("selectFile", this.data);
to that:
formData.append("file", this.data);
Cause
public ResponseEntity<String> handleFileUpload(@RequestParam("file")
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)