使用带有 axios、文件类型的 Node JS 下载文件并确定 MIME 类型

Downloading a file and determining MIME type with Node JS with axios, file-type

我想下载一个文件并确定它的 MIME 类型。为此,我正在使用 axiosfile-type 库。

这是我的代码:

async function download(url) {
    const response = await axios.get(url, {
        responseType: "arrayBuffer"
    });
    const buffer = Buffer.from(response.data, "binary");
    console.log(buffer); // <Buffer fd fd fd fd 00 10 4a 46 49 46 00 01 01 00 00 01 00 01 00 00 fd fd 00 fd 00 09 09 0a 08 0a 08 0b 0b 09 0b 0a 0b 0b 0b 0e 10 0c 0a 0b 0d 13 17 15 10 14 ... 54078 more bytes>

    const type = await FileType.fromBuffer(buffer);
    console.log(type); // undefined
}

出于某种原因,type 总是在这里 undefined,无论 URL 是什么。

问题实际上与 axios 有关。而不是 "arrayBuffer" 使用全部小写:"arraybuffer"