首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >在Axios和NodeJS中使用内容部署

在Axios和NodeJS中使用内容部署
EN

Stack Overflow用户
提问于 2020-12-04 17:23:07
回答 1查看 60关注 0票数 0

大家好,我正在使用nodejs并尝试来自https://www.lalal.ai/api/help/的应用程序接口

代码语言:javascript
运行
复制
$ curl --url https://www.lalal.ai/api/upload/ --data-binary @any_file.mp3 --header "Content-Disposition: attachment; filename=any_file.mp3" --header "Authorization: license 14abcde0"

这是我的代码

代码语言:javascript
运行
复制
app.post("/uploads", upload.any("tmparr"), async (req, res, next) => {
  const ucuk = req.files[0];
  // console.log(ucuk);

  Axios.post("https://www.lalal.ai/api/upload/", {
    headers: {
      "Content-Disposition": `attachment; filename=${ucuk.path}`,
      Authorization: "license ec2a55f4",
    },
  }).then((res) => {
    console.log(res);
  });
})

我得到了这个错误

代码语言:javascript
运行
复制
(node:31608) UnhandledPromiseRejectionWarning: Error: Request failed with status code 405
    at createError (D:\reactjs\crud-mern\server\node_modules\axios\lib\core\createError.js:16:15)
    at settle (D:\reactjs\crud-mern\server\node_modules\axios\lib\core\settle.js:17:12)

谁能给我解释一下为什么这是错误,以及如何修复它?:D

EN

回答 1

Stack Overflow用户

发布于 2020-12-04 22:22:55

axios.post使用的三个参数:

  1. data
  2. config (您正在发布配置数据的URL和配置文件)

你错过了2号。

您似乎还在content-disposition头中传递了完整路径,而不仅仅是文件名。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/65140938

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档