Mini Program sent the picture directly to Ali oss.

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.
clipboard.png
1: what is the reason why the uploaded file address is not returned?
2: what is the solution?


the new address after success should be spliced by yourself:

  //
   oss = url + key
MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1c2a399-15f0f.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1c2a399-15f0f.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?