微信小程序对接阿里云视频点播,备忘

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

猜你喜欢

转载自www.cnblogs.com/murenhui/p/10674893.html