I'm trying to send an excel file to my back-end via POST request and no results yet. My back-end is prepared with the right maven dependency to read an excel file, which is poi-ooxml. The problem is to send.
I'm using Angular 6(front-end) | SpringBoot RESTful API(back-end) | PrimeNG
What I have so far >>>
HTML
<p-fileUpload name="demo[]" customUpload="true" (uploadHandler)="onAttachmentsUpload($event)" maxFileSize="1000000"></p-fileUpload>
TYPESCRIPT
onAttachmentsUpload(event) {
const file = event.files[0];
console.log(file);
const reader = new FileReader();
let binary;
if(file) {
reader.onprogress = e => {
const rawData = reader.result;
};
reader.onload = e => {
const rawData: any = reader.result;
this.bdpService.getExcelBodyContent(btoa(rawData)).subscribe(
result => {
console.log(result);
},
err => console.error(err)
);
};
reader.readAsBinaryString(file);
} }
SERVICE.TS
getExcelBodyContent(frmData: any) {
const data = {
file: frmData
}
return this.http.post<JSON>(`${environment.API_BDP_FILE_UPLOAD_URL}`, data);
}