const fs = require("fs");
axios.post("https://api.weixin.qq.com/tcb/uploadfile?access_token=access_token",
{
env: "env",
path: "JavaScipt\\Test.json"
},
{
headers: {
contentType: "multipart/form-data"
}
}
).then(res => {
console.log(res.data);
let parm = res.data;
let form = {
"key": "JavaScipt\\Test.json",
"x-cos-security-token": parm.token,
"Signature": parm.authorization,
"x-cos-meta-fileid": parm.cos_file_id,
"file": fs.readFileSync("JavaScipt\\Test.json")
};
axios.post(parm.url, form).then(res => {
console.log(res.data);
}).catch(err => {
console.log(err);
})
}).catch(err => {
})
第一步用json请求,上传文件用form-data, 你顺序给搞反了