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>
Component.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);
)}
}
我哪里弄错了?
解决方法:
这个:
formData.append("selectFile", this.data);
对此:
formData.append("file", this.data);
原因
public ResponseEntity<String> handleFileUpload(@RequestParam("file")
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。