1

I'm trying to send post request to url with an excel file that exists in a path but all the examples I tried tries to parse excel file. How can I send excel file as it is using the below code?

This is the method

static async postRequestForExcelUpload(url: string, query: object, token: string, file: object) {
        try {
            return  await requestify.request(url, {
                method: 'POST',
                data: file,
                query: query,
                headers: {
                    Authorization: token,
                    "Content-Type": "multipart/form-data"
                },
            });
        } catch (error) {
            return error
        }
    }

and this is how I try to add my excel file

 let path = "exceluploadfiles/excel.xlsx";

        let data = new FormData();
        await data.append("xlsx", await xlsx.readFile(path, {type: "file"}));

        let responseEndpoint = await RestClient.postRequestForExcelUpload(
            "/uploadexcel",
            query,
            token,
            data
        );
Utku
  • 11
  • 1
  • 5
  • the `xlsx` library you are using already parsed the file before you send it, consider reading it normally into a buffer instead – Krzysztof Krzeszewski Jul 05 '19 at 07:38
  • I tried **fs.readFileSync** instead but backend returns this `Response { code: 500, headers: { 'x-frame-options': 'SAMEORIGIN', 'x-xss-protection': '1; mode=block', 'x-content-type-options': 'nosniff', 'strict-transport-security': 'max-age=31536000; includeSubDomains', 'set-cookie': [ 'ARRAffinity='some-long-string';Path=/;HttpOnly;Domain=xx' ], date: 'Fri, 05 Jul 2019 07:46:52 GMT', connection: 'close', 'content-length': '0' }, body: '' }` do you have any idea why this is happening? @KrzysztofKrzeszewski – Utku Jul 05 '19 at 07:50

0 Answers0