Error when finding out the type of file retrieved with axios and transformed into a buffer

Viewed 12

I have a problem finding out the type of a file. I take the file from axios but when I try to find out the type of the file I get undefined My code

export const uploadFileToServer = async (path: string, feedLocation: string, fileName: string) => {
    // @ts-ignore
    let uploadPath = `./storage/${path}/${fileName}.csv`;

    const { fileTypeFromBuffer } = await (eval('import("file-type")') as Promise<typeof import('file-type')>);

    const response = await axios.get(feedLocation, {responseType: "arraybuffer"});
    const buffer = Buffer.from(response.data, "binary");
    const test = await fileTypeFromBuffer(buffer);

    console.log("TEST", test);
    fs.writeFile(uploadPath, buffer, (err) => {
        if (!err) console.log('Data written');
    });

0 Answers
Related