axios 通过本地文件路径上传文件

时间:2021-07-14 17:47:48

标签: node.js curl axios form-data

我正在连接一个只接受本地文件路径的文件上传 API。此调用的 curl 示例是:

curl -L -X POST 'https://the.domain/file'
-F 'file=@"/home/dummy.pdf"'

在我的 nodejs 代码中,我试图将表单数据附加到它,但它不起作用。

const formData = new FormData();
formData.append(filename, content);

await axios.post('https://the.domain/file', formData);

文件上传 API 返回未上传文件。似乎 -F 'file=@localpath' 不能直接转换成表单数据?。如何使用 axios 从我的本地文件路径上传文件?

0 个答案:

没有答案