Unable to upload same file twice. If uploading different files its working
Error under Network in chrome
{ timeStamp: ......, status: 417
error: 'Bad Request',
message: 'Required request part 'file' is not present'
path: 'url as hosted on Tomcat'
}
Spring Boot Controller.java file
@PostMapping("/Post")
public ResponseEntity<String> handleFileUpload(@RequestParam("file")
MultipartFile file){ String Message=""; try .......(and so on)}
My Angular Component
<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 file
fileEvent(e) {
this.data = e.target.files[0];
}
onSubmit() {
let headers: any = new Headers();
headers.append('Content-type', 'undefined');
let formData = new FormData();
formData.append("file", 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);
)}
}
Where am I making a mistake?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…