微信小程序云开发如何实现上传视频 以及 图片
最基础的数据库增删改查,上传到云存储即可实现,附源码
wxml文件
<button bindtap="upload">上传文件</button>
<button bindtap="uploadvideo">上传视频</button>
<video src="{{videoUrl}}"></video>
js文件
Page({
data: {
imgURL:"",
videoUrl:""
},
upload() {
var myDate = new Date();
let time = myDate.getTime();
console.log("点击了上传")
wx.chooseImage({
count: 1,
sizeType: ['original', 'compressed'],
sourceType: ['album', 'camera'],
success (res) {
console.log("选择成功",res);
console.log(time),
wx.cloud.uploadFile ({
cloudPath: time + '.png',
filePath: res.tempFilePaths[0],
success: res => {
console.log("上传成功",res);
},
fail:console.error
})
}
})
},
uploadvideo() {
console.log("点击了上传视频");
wx.chooseVideo({
sourceType: ['album','camera'],
maxDuration: 60,
camera: 'back',
success(res) {
console.log("选择视频成功",res);
wx.cloud.uploadFile ({
cloudPath: 'aaa.mp4',
filePath: res.tempFilePath,
success: res => {
console.log("上传成功",res);
},
fail:console.error
})
}
})
}
})