zoukankan      html  css  js  c++  java
  • 微信小程序对接阿里云视频点播,备忘

    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

  • 相关阅读:
    day3---字符串的索引与切片
    day4---int bool str之间相互转换
    day3---数据类型整体分析
    day2---while else
    day2---运算符
    day2---格式化输出
    ES6-04 Promise设计 类 模块
    jquery02-效果动画
    jquery01-基础使用
    bootstrap-03 常用重要组件(2)
  • 原文地址:https://www.cnblogs.com/murenhui/p/10674893.html
Copyright © 2011-2022 走看看