search
HomeWeChat AppletMini Program DevelopmentDevelopment code for uploading videos in WeChat applet

Development code for uploading videos in WeChat applet

Sep 06, 2018 am 10:54 AM
WeChat appletVideo upload

The content of this article is about the development code for uploading videos in the WeChat applet. It has certain reference value. Friends in need can refer to it. I hope it will be helpful to you.

In fact, this is relatively simple. The official API interface is provided. Basically, you can call it directly. Without further ado, the 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:

WeChat JSSDK upload pictures_javascript skills

AJAX asynchronously collects all images from Youku album Video and information (JavaScript code)_javascript skills

The above is the detailed content of Development code for uploading videos in WeChat applet. For more information, please follow other related articles on the PHP Chinese website!

Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

SecLists

SecLists

SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

EditPlus Chinese cracked version

EditPlus Chinese cracked version

Small size, syntax highlighting, does not support code prompt function

SublimeText3 Linux new version

SublimeText3 Linux new version

SublimeText3 Linux latest version

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment