微信小程序對接阿里雲視頻點播,備忘


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
                   })
                 },
               })
             }
           })
View Code

 

參考:

 https://www.cnblogs.com/HfdBlog/p/9866369.html


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM