简体   繁体   English

将内容处置与 Axios 和 NodeJS 一起使用

[英]Use content-disposition with Axios and NodeJS

Hi guys I'm using nodejs and trying the API from https://www.lalal.ai/api/help/大家好,我正在使用nodejs并尝试来自https的API://www.lalal.ai/api/help/

$ 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"

This is my code这是我的代码

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);
  });
})

And I got this error我得到了这个错误

(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)

Can someone explain to me why that is error and how to fix it?有人可以向我解释为什么这是错误以及如何解决吗? :D :D

axios.post takes three arguments: axios.post需要三个arguments:

  1. The URL URL
  2. The data you are posting您发布的数据
  3. The config配置

You've missed out number 2.你错过了2号。

You also seem to be passing the full path in the content-disposition header instead of just the file name.您似乎还传递了content-disposition header 中的完整路径,而不仅仅是文件名。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM