[英]Use content-disposition with Axios and NodeJS
大家好,我正在使用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"
這是我的代碼
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);
});
})
我得到了這個錯誤
(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
axios.post
需要三個arguments:
你錯過了2號。
您似乎還傳遞了content-disposition
header 中的完整路徑,而不僅僅是文件名。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.