
upvideo(){ var aliOssParams = util.aliOssParams();//主要是獲取上傳阿里雲的加密策略policy和簽名signature;以及上傳自己要上傳到阿里雲的地址,當然還有自己阿里雲accessid。 //上傳視頻到阿里雲 var that = this; wx.chooseVideo({ maxDuration: 10, success: function (res) { var tempFilePath = res.tempFilePath; var stringFilePath = String(tempFilePath); var indexType = stringFilePath.lastIndexOf('.'); var type = stringFilePath.substring(indexType); var alikey = 'video/'+new Date().getTime() + Math.floor(Math.random() * 1000)+ type ;//隨機1000內的數加上時間戳作為你存放在阿里雲video目錄下名字和類型。 wx.uploadFile({ url:aliOssParams.host, filePath: tempFilePath, name: 'file', formData: { name: tempFilePath, key: alikey,//這個是關鍵它是定義存放在阿里雲那個目錄下 policy:aliOssParams.policy,//上傳阿里雲的加密策略 OSSAccessKeyId: aliOssParams.aid,//自己阿里雲的aid success_action_status: "200", signature: aliOssParams.signature,//上傳阿里雲的簽名 }, success: function (res) { var videoUrl = aliOssParams.host+'/'+alikey;//這就是 剛上傳阿里雲后的存放的地址鏈接,通過它打開你剛上傳視頻。 that.videoUrl = videoUrl; console.log('that',that,videoUrl); wx.showToast({ title: "上傳成功", icon: 'success', duration: 1000 }) }, fail: function ({ errMsg }) { wx.showToast({ title: "上傳失敗", duration: 1000 }) }, }) } })
參考: