refer to Ali official document
process:
1: download web direct upload demo code, upload images to obtain signature,policy
2: upload pictures through Mini Program upload API (wx.chooseImage to obtain local temporary file path)
/**
* oss
* file:
* dir: oss
*/
function uploadOss(file, dir){
return new Promise((resolve, reject)=>{
let key = `${dir}${util.formatTime(new Date().getTime(), "YY-MM-DD")}/${new Date().getTime()}.png`;
console.log(key)
wx.uploadFile({
url: "https://xxx.aliyuncs.com", //
filePath: file,
name: "file",
formData: {
name: file,
key: key,
policy: "xxx",
OSSAccessKeyId: "xxx",
success_action_status: "200",
signature: "xxx"
},
success: function(res) {
console.log(res)
resolve(res)
},
fail: function(err){
console.error(err)
reject(err)
}
})
})
}
wx.chooseImage({
sizeType: ["compressed"],
count: count,
success: function(res) {
let file = res.tempFilePaths[0];
Base.uploadOss(file, "imgs/comment/")
...
}
})
calls the uploadOss method to successfully enter resolve, but the printed res result is not satisfactory.
1: what is the reason why the uploaded file address is not returned?
2: what is the solution?