腾讯云点播小程序端上传 SDK

云点播是专门应对上传大视频文件的。

腾讯云点播文档:https://cloud.tencent.com/document/product/266/18177

这个文档比较简单,实在不行,把demo下载下来,一看就明白了,然后再揉一下挪到自己的项目里。完事。

getSignature: function(callback) {

uni.request({

url: 'https://www.xxx.com/mnp/zsapi/getSignature.php',

method: 'POST',

data: {

mid: uni.getStorageSync('mid'),

token: uni.getStorageSync('token')

},

header: {

'content-type': 'application/x-www-form-urlencoded'

},

success: function(res) {

if (res.data.signature) {

callback(

res.data.signature

);

} else {

return '获取签名失败';

}

}

});

},

ChooseImage(e) {

console.log(e)

let that = this

// 选择多张图片

uni.chooseMedia({

count: 15, // 最多可以选择的图片张数

mediaType: ['image', 'video'],

sizeType: ['compressed'], // 可以指定是原图还是压缩图

sourceType: ['album'], // 可以指定来源是相册还是相机

// maxDuration: 30,

// camera: 'back',

success: function(res) {

console.log(res, res.tempFiles[0], '???')

if (res.type == 'video') {

if (e == '0') {

uni.showToast({

title: '第一张必须上次图片',

duration: 2000,

icon: 'none'

})

return

}

//选择视频

that.videoFile = res.tempFiles[0]

setTimeout(() => {

that.startUpload(e)

}, 500)

复制代码
					} else {
						// 选择图片成功,res.tempFiles 包含选择的图片路径列表
						uni.showLoading({
							title: '上传中...'
						})
						// console.log(res.tempFiles)
						that.uploadDIY( res.tempFiles, 0, 0, 0,  res.tempFiles.length,e);
						return
						for (let i = 0; i < res.tempFiles.length; i++) {

							uni.uploadFile({
								url: 'https://www.xxx.com/mnp/zsapi/gongdi_upload.php',
								filePath: res.tempFiles[i].tempFilePath,
								name: 'file',
								formData: {
									'mid': uni.getStorageSync('mid'),
									'token': uni.getStorageSync('token'),
								},
								success(res) {
									const data = JSON.parse(res.data.replace('\uFEFF',
										''))
									console.log(data)
									if (data.bs == 'success') {
										uni.showToast({
											title: data.errmsg,
											duration: 2000,
											icon: 'success'
										})
										that.infolist[e].imglist.push(data.img)
									} else if (data.bs == 'guoqi') {
										uni.showToast({
											title: data.errmsg,
											duration: 2000,
											icon: 'error'
										})
										setTimeout(function() {
											uni.redirectTo({
												url: '../../pagesD/login/login'
											})
										}, 500)
									} else {
										uni.showToast({
											title: data.errmsg,
											duration: 2000,
											icon: 'error'
										})
									}
								},
								fail() {
									uni.showToast({
										title: '服务器繁忙,请稍后再试',
										duration: 2000,
										icon: 'error'
									})
								}
							})
						}
					}
				}
			})
		},
		startUpload(e) {
			let that = this
			uni.showLoading({
				title: '上传中...',
				mask: true,
			})
			const self = this;
			const uploader = VodUploader.start({
				mediaFile: self.videoFile, //必填,把chooseVideo回调的参数(file)传进来
				getSignature: self.getSignature, //必填,获取签名的函数
				error: function(result) {
					console.log("error");
					console.log(result);
					// uni.hideLoading();
					uni.showModal({
						title: "上传失败",
						content: JSON.stringify(result),
						showCancel: false
					});
				},
				progress: function(result) {
					console.log("progress");
					console.log(result);
					// uni.hideLoading();
					self.progress = parseInt(result.percent * 100)
				},
				finish: function(result) {
					console.log("finish");
					console.log(result);
					let brr = []
					let obj = {}
					obj.url = result.videoUrl
					brr.push(`myvideo${e}`)
					that.videoarr = brr
					obj.id =  `myvideo${e}`
					self.infolist[e].videolist.push(obj)
					uni.showToast({
						title: '上传成功',
						duration: 2000,
						icon: 'success'
					})
					self.reset();
				}
			});
			this.uploader = uploader
		},
		uploadDIY(filePaths, successUp, failUp, i, length,e) {
			let that = this
			uni.uploadFile({
				url: 'https://www.xxxx.com/mnp/zsapi/gongdi_upload.php',
				filePath: filePaths[i].tempFilePath,
				name: 'file',
				formData: {
					'mid': uni.getStorageSync('mid'),
					'token': uni.getStorageSync('token'),
				},
				success: (res) => {
					const data = JSON.parse(res.data.replace('\uFEFF',''))
					if (data.bs == 'success') {
						uni.showToast({
							title: data.errmsg,
							duration: 2000,
							icon: 'success'
						})
						successUp++;
						// console.log('上传图片成功:', JSON.parse(res.data));
						// var data = JSON.parse(res.data);
						// console.log(data)
						// 把获取到的路径存入imagesurl字符串中
						that.infolist[e].imglist.push(data.img)
						// console.log(this.data.imagesurl)
					} else if (data.bs == 'guoqi') {
						uni.showToast({
							title: data.errmsg,
							duration: 2000,
							icon: 'error'
						})
						setTimeout(function() {
							uni.redirectTo({
								url: '../../pagesD/login/login'
							})
						}, 500)
					} else {
						uni.showToast({
							title: data.errmsg,
							duration: 2000,
							icon: 'error'
						})
					}
					
				},
				fail: (res) => {
					failUp++;
				},
				complete: () => {
					i++;
					if (i == length) {
						// Toast('总共' + successUp + '张上传成功,' + failUp + '张上传失败!');
					} else { //递归调用uploadDIY函数
						that.uploadDIY(filePaths, successUp, failUp, i, length,e);
					}
				},
			});
			
		},
相关推荐
西猫雷婶30 分钟前
STAR-CCM+|K-epsilon湍流模型溯源
大数据·云计算
CRMEB定制开发2 小时前
CRMEB私域电商系统后台开发实战:小程序配置全流程解析
小程序·开源软件·小程序商城·商城源码·微信商城·crmeb
2501_915106325 小时前
iOS混淆工具实战 金融支付类 App 的安全防护与合规落地
android·ios·小程序·https·uni-app·iphone·webview
從南走到北7 小时前
JAVA国际版东郊到家同城按摩服务美容美发私教到店服务系统源码支持Android+IOS+H5
android·java·开发语言·ios·微信·微信小程序·小程序
Summer不秃7 小时前
uniapp 手写签名组件开发全攻略
前端·javascript·vue.js·微信小程序·小程序·html
两张不够花8 小时前
Shell脚本源码安装Redis、MySQL、Mongodb、PostgreSQL(无报错版)
linux·数据库·redis·mysql·mongodb·postgresql·云计算
牛奶咖啡1311 小时前
云计算之云主机Linux是什么?有何配置?如何选?
云计算·linux的发行版如何选·云主机操作系统如何选·云主机的快照与镜像功能·云主机选型考虑哪些因素·云主机的配置如何选
牛奶咖啡1311 小时前
云计算核心技术之云网络技术
云计算·负载均衡·云网络技术·专有/私有网络vpc·vpc系统架构·云网络关键技术·容器云网络技术
lucky_lyovo11 小时前
大模型部署
开发语言·人工智能·云计算·lua
井云AI18 小时前
井云智能体封装小程序:独立部署多开版 | 自定义LOGO/域名,打造专属AI智能体平台
人工智能·后端·小程序·前端框架·coze智能体·智能体网站·智能体小程序