I am currently facing an issue with uploading a file that was recently downloaded using Angular2 to a Spring API Rest.
The problem being displayed on the Spring app is as follows...
The request was rejected because no multipart boundary was found
at org.apache.tomcat.util.http.fileupload.FileUploadBase$FileItemIteratorImpl.(FileUploadBase.java:831) ~[tomcat-embed-core-8.5.28.jar:8.5.28] at org.apache.tomcat.util.http.fileupload.FileUploadBase.getItemIterator(FileUploadBase.java:256) ~[tomcat-embed-core-8.5.28.jar:8.5.28] at org.apache.tomcat.util.http.fileupload.FileUploadBase.parseRequest(FileUploadBase.java:280) ~[tomcat-embed-core-8.5.28.jar:8.5.28] at org.apache.catalina.connector.Request.parseParts(Request.java:2869) ~[tomcat-embed-core-8.5.28.jar:8.5.28] at org.apache.catalina.connector.Request.parseParameters(Request.java:3216) ~[tomcat-embed-core-8.5.28.jar:8.5.28] at org.apache.catalina.connector.Request.getParameter(Request.java:1137) ~[tomcat-embed-core-8.5.28.jar:8.5.28]
The client side sends the request with "multipart/form-data" as the content-type.
How can this issue be resolved?
fileDownloaderService
upload(file) {
const formData = new FormData();
formData.append('file', file);
const req = new HttpRequest('POST', this.urlUpload, file, {
headers: new HttpHeaders({'Content-Type':'multipart/form-data'}),
reportProgress: true
});
return this.http.request(req);
}
app.component
upload() {
let file = this.generate_dummy_file(50000000);
this.downloader.upload(file).subscribe( event => {
if (event.type === HttpEventType.UploadProgress) {
} else if (event instanceof HttpResponse) {
console.log('File is completly uploaded!');
}
});
}
generate_dummy_file(size) {
return new Blob([new ArrayBuffer(size)], {type: 'multipart/form-data'});
};
And spring side
@PostMapping("/uploadFile")
public UploadFileResponse uploadFile(@RequestParam("file") MultipartFile file) {
return ...;
}
Thank you for your assistance