Home  >  Article  >  WeChat Applet  >  How to implement video upload function in small program development

How to implement video upload function in small program development

王林
王林forward
2020-12-17 09:07:574210browse

How to implement video upload function in small program development

Note:

Since the official API is provided, we can implement it by calling it directly.

(Learning video sharing: Programming video)

The specific code is as follows:

index.wxml

 <view class="page-body-info">
      <block wx:if="{{src === &#39;&#39;}}">
        <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>
      </block>
      <block wx:if="{{src != &#39;&#39;}}">
        <video src="{{src}}" class="video"></video>
      </block>
    </view>

index.js

Page({
  data: {
    src: &#39;&#39;
  },
 //选择视频
  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: &#39;http://172.16.98.36:8080/upanddown/upload2&#39;,//服务器接口
      method: &#39;POST&#39;,//这句话好像可以不用
      filePath: src,
      header: {
        &#39;content-type&#39;: &#39;multipart/form-data&#39;
      },
      name: &#39;files&#39;,//服务器定义的Key值
      success: function() {
        console.log(&#39;视频上传成功&#39;)
      },
      fail: function() {
        console.log(&#39;接口调用失败&#39;)
      }
    })
  }
})

Related recommendations: 小program development tutorial

The above is the detailed content of How to implement video upload function in small program development. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:csdn.net. If there is any infringement, please contact admin@php.cn delete