http api 调用uploadfile方法后上传图片到COS后 一直报405 如何解决?
前端vue + ivew ,后端 express
1.使用ivew的upload组件上传文件
//url:https://api.weixin.qq.com/tcb/uploadfile?access_token=38_k2fIU6pgi2GC_jSRyMLwzPoDRXklDi-upZBK9t5sVUTPNqRoNKJ8H3h8PqYTWoDfg3P2733YBXJuufBK8Ty_uNhjqFHNqHS68X4q4Stxtv-8yrGSuIDiLAw1g3pPIXICmesF5NNR6YJ54vguQCKaAEAFRZ
router.post('/',function (req, res, next) {
var uploadDir = path.resolve(__dirname, basepath) + "/"//basepath = "../../static/uploads/"
var form = new multiparty.Form({uploadDir:uploadDir})
form.encoding = 'utf-8'
form.maxFilesSize = 10 * 1024 * 1024
form.parse(req,function(err,fields,files){
if(err){
console.log(err)
}else{
console.log(files)
var filepath = files.file[0].path
//console.log(fields)
$http.post(`/tcb/uploadfile?access_token=${req.query.token}`,{
"env": "wecloudv100-lxg5c",
"path": UPLOADPATH //UPLOADPATH = "uploads"
}).then(response=>{
//response 返回Signature等参数
postImageToCloud(res,response,filepath,files.file[0]) //处理上传图片到cos
}).catch(err=>{
res.status(403).send({"code":403,error:err})
})
}
})
})
返回结果
调用postImageToCloud
function postImageToCloud(res,params,filepath,file){
try{
let filename = UPLOADPATH + "/111.png" //filename = 'uploads/111.png'
$http.postform({
headers:{
'Content-Type': 'multipart/form-data;charset=utf-8;'
},
url: params.url,
method: 'post',
formData:{
"Signature": params.authorization,
"key": filename,
"x-cos-security-token": params.token,
"x-cos-meta-fileid": params.cos_file_id,
"file": {
value: fs.createReadStream(filepath),
options: {
filename: file.originalFilename,
contentType: 'image/x-png'
}
}
}
}).then(response=>{
res.status(200).send(response)
}).catch(err=>{
console.log("$http.post postImageToCloud catch:"+JSON.stringify(err))
res.status(405).send({"code":405,error:err,url:params.url})
})
}catch(e){
res.status(200).send({error:e})
}
}
到这里就报错了
在postman里面就能成功
这个message里面的405是什么鬼 我哪步错了?