
说明:
由于官方提供了API,所以我们直接调用就可以实现了。
(学习视频分享:编程视频)
具体代码如下:
index.wxml
1 2 3 4 5 6 7 8 9 10 11 12 | <view class = "page-body-info" >
<block wx: if = "{{src === ''}}" >
<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 != ''}}" >
<video src= "{{src}}" class = "video" ></video>
</block>
</view>
|
Salin selepas log masuk
index.js
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 | Page({
data: {
src: ''
},
chooseVideo: function () {
var that = this
wx.chooseVideo({
success: function (res) {
that.setData({
src: res.tempFilePath,
})
}
})
},
uploadvideo: function () {
var src = this.data.src;
wx.uploadFile({
url: 'http:
method: 'POST',
filePath: src,
header: {
'content-type': 'multipart/form-data'
},
name: 'files',
success: function () {
console.log('视频上传成功')
},
fail: function () {
console.log('接口调用失败')
}
})
}
})
|
Salin selepas log masuk
相关推荐:小程序开发教程
Atas ialah kandungan terperinci 小程序开发怎么实现视频上传功能. Untuk maklumat lanjut, sila ikut artikel berkaitan lain di laman web China PHP!