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);
}
4
  • 1
    can you share a code snippet of what you've done so far, in the meantime, you can check this answer: stackoverflow.com/questions/47936183/angular-file-upload Commented Jun 25, 2019 at 12:56
  • Please refer this link stackoverflow.com/questions/48279484/… Commented Jun 25, 2019 at 12:59
  • Please provide some more details and information and code so we can dig deeper for a good solution. Commented Jun 25, 2019 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! Commented Jun 25, 2019 at 16:31

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.