微信小程序中实现上传视频的开发代码

index.wxml

<view class="image-plus image-plus-nb" bindtap="chooseVideo">

  <view class="image-plus-horizontal"></view>

  <view class="image-plus-vertical"></view>

</view>

<view class="image-plus-text">添加视频</view>
<video src="{{src}}" class="video"></video>
index.js

Page({

  data: {

src: ''

},

//选择视频

chooseVideo: function() {

var that = this

wx.chooseVideo({

  success: function(res) {

    that.setData({

      src: res.tempFilePath,

    })

  }

})

},

//上传视频 目前后台限制最大100M,以后如果视频太大可以在选择视频的时候进行压缩

uploadvideo: function() {

var src = this.data.src;

wx.uploadFile({

  url: 'http://172.16.98.36:8080/upanddown/upload2',//服务器接口

  method: 'POST',//这行好像可以不用

  filePath: src,

  header: {

    'content-type': 'multipart/form-data'

  },

  name: 'files',//服务器定义key字段名称

  success: function() {

    console.log('视频上传成功')

  },

  fail: function() {

    console.log('接口调用失败')

  }

})

  }

})

猜你喜欢

转载自blog.csdn.net/wxb8826206/article/details/84854515