uniapp vue3中app端使用腾讯云点播上传

在项目中有个需求是视频需要上传到腾讯云点播里面,打算使用uniapp的插件

插件地址

https://ext.dcloud.net.cn/plugin?id=2750

首先在uniapp插件市场导入插件

去manifest.json的原生插件配置导入

然后去打自定义基座

引入插件

复制代码
	var UGCUpload = uni.requireNativePlugin("RY-TencentUGCUpload");

获取上传签名后端生成的

javascript 复制代码
// 获取上传签名的函数

	const getSignature = () => {
		return new Promise((resolve, reject) => {
			request({
				url: '/app/tencentCloudOnDemand/signature',
				method: 'GET',
			}).then(res => {
				resolve(res.data)
			}).catch(error => {
				reject(error)
			})
		});
	}

签名生成文档

https://cloud.tencent.com/document/product/266/9221

验证签名是否正确

https://vod-tool.vod-qcloud.com/ugcdecode?lang=zh

初始化插件

javascript 复制代码
const signature = ref();
	
	onReady(async () => {
		const res = await getSignature();
		console.log(res, "当前获取到的参数1");
		signature.value=res;
        //初始化
		UGCUpload.init({
			userId: 'test001',
			signature: res
		}, ret => {
			console.log(ret);
		});
        //获取上传的进度
		UGCUpload.setVideoListener({}, ret => {
			console.log(ret, 'setVideoListener');
		});
	})

点击按钮触发函数

javascript 复制代码
const goVideoUpload = () => {
		uni.chooseVideo({
			sourceType: ['camera', 'album'],
			success: function(res) {
				let tempPath = res.tempFilePath;
				let videoPath = plus.io.convertLocalFileSystemURL(tempPath);
				console.log(tempPath,videoPath,"当前获取的文件")
				goUploadPublishVideo(videoPath);
			}
		});
	}

调用插件上传方法

javascript 复制代码
const goUploadPublishVideo = (videoPath) => {
		console.log(videoPath,"当前获取的文件goUploadPublishVideo")
		console.log( signature.value,"当前获取的签名signature")
		
		UGCUpload.publishVideo({
			signature: signature.value,
			videoPath: videoPath
		}, ret => {
			console.log(ret, "publishVideo");
		});

	}

完整代码

javascript 复制代码
<template>
	<view>
		<button @click="goVideoUpload">上传视频</button>
	</view>
</template>

<script setup>
	var UGCUpload = uni.requireNativePlugin("RY-TencentUGCUpload");
	import {
		ref
	} from 'vue';
	import {
		onReady
	} from '@dcloudio/uni-app'
	import request from '@/common/request.js'
	// 获取上传签名的函数

	const getSignature = () => {
		return new Promise((resolve, reject) => {
			request({
				url: '/app/tencentCloudOnDemand/signature',
				method: 'GET',
			}).then(res => {
				resolve(res.data)
			}).catch(error => {
				reject(error)
			})
		});
	}
	const signature = ref();
	
	onReady(async () => {
		const res = await getSignature();
		console.log(res, "当前获取到的参数1");
		signature.value=res;
		UGCUpload.init({
			userId: 'test001',
			signature: res
		}, ret => {
			console.log(ret);
		});
		UGCUpload.setVideoListener({}, ret => {
			console.log(ret, 'setVideoListener');
		});
	})
	const goVideoUpload = () => {
		uni.chooseVideo({
			sourceType: ['camera', 'album'],
			success: function(res) {
				let tempPath = res.tempFilePath;
				let videoPath = plus.io.convertLocalFileSystemURL(tempPath);
				console.log(tempPath,videoPath,"当前获取的文件")
				goUploadPublishVideo(videoPath);
			}
		});
	}

	const goUploadPublishVideo = (videoPath) => {
		console.log(videoPath,"当前获取的文件goUploadPublishVideo")
		console.log( signature.value,"当前获取的签名signature")
		
		UGCUpload.publishVideo({
			signature: signature.value,
			videoPath: videoPath
		}, ret => {
			console.log(ret, "publishVideo");
		});

	}
</script>

<style>

</style>
相关推荐
2501_915106322 小时前
app 上架过程,安装包准备、证书与描述文件管理、安装测试、上传
android·ios·小程序·https·uni-app·iphone·webview
m0_694845572 小时前
tinylisp 是什么?超轻量 Lisp 解释器编译与运行教程
服务器·开发语言·云计算·github·lisp
2501_915106322 小时前
使用 Sniffmaster TCP 抓包和 Wireshark 网络分析
网络协议·tcp/ip·ios·小程序·uni-app·wireshark·iphone
ESBK20252 小时前
第四届移动互联网、云计算与信息安全国际会议(MICCIS 2026)二轮征稿启动,诚邀全球学者共赴学术盛宴
大数据·网络·物联网·网络安全·云计算·密码学·信息与通信
宠友信息3 小时前
2025社交+IM及时通讯社区APP仿小红书小程序
java·spring boot·小程序·uni-app·web app
“负拾捌”4 小时前
python + uniapp 结合腾讯云实现实时语音识别功能(WebSocket)
python·websocket·微信小程序·uni-app·大模型·腾讯云·语音识别
_运维那些事儿15 小时前
VM环境的CI/CD
linux·运维·网络·阿里云·ci/cd·docker·云计算
人间打气筒(Ada)18 小时前
k8s:CNI网络插件flannel与calico
linux·云原生·容器·kubernetes·云计算·k8s
主机哥哥1 天前
2026年阿里云五种方案快速部署 OpenClaw(Clawdbot)详细教程
阿里云·云计算
局外人LZ1 天前
Uniapp脚手架项目搭建,uniapp+vue3+uView pro+vite+pinia+sass
前端·uni-app·sass