1

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);
}
Vdalk
  • 11
  • 4
  • 1
    can you share a code snippet of what you've done so far, in the meantime, you can check this answer: https://stackoverflow.com/questions/47936183/angular-file-upload – macphilips Jun 25 '19 at 12:56
  • Please refer this link https://stackoverflow.com/questions/48279484/sending-file-object-to-spring-rest-controller-through-angular-5/48295301#48295301 – hrdkisback Jun 25 '19 at 12:59
  • Please provide some more details and information and code so we can dig deeper for a good solution. – Himanshu Bansal Jun 25 '19 at 12:59
  • @hrdkisback thx for the help. Now I can send and read the file. Also, after reading, it's returning a JSON result. It's just perfect! – Vdalk Jun 25 '19 at 16:31

0 Answers0