I am trying to upload a file on client side and send HTTP Post request to Spring Rest Controller. But when I receive the file object in Rest controller I could see it as \'n
the easiest thing to do (according to me) is to use a FormData object.
Here is how :
@viewChild() fileInput: ElementRef;
onFileChange(event) {
const files = this.fileInput.nativeElement.files as FileList;
const file = files.item(0);
const formData = new FormData();
formData.append('pdf', file, file.name);
this.http.post('abc', formData, {
headers: new HttpHeaders().set('content-type','application/pdf')
}).subscribe(
data => console.log(data),
err => console.log(err)
);
}
Try this and tell me what you see on Spring side.