uniapp上传视频

uploadVideo() {

uni.chooseVideo({

sourceType: ['album', 'camera'], // 可以指定来源是相册还是相机,默认二者都有

maxDuration: 60, // 拍摄视频最长拍摄时间,单位秒

camera: 'back', // 默认为后置摄像头

success: (res) => {

this.videoPath = res.tempFilePath;

console.log('选择的视频路径:', this.videoPath);

this.startUpdata(this.videoPath)

},

fail: (err) => {

console.error('选择视频失败:', err);

}

});

},

startUpdata(e) {

const uploadTask = uni.uploadFile({

url:'http://192.168.31.221:8080/common/upload', // 开发者服务器地址

filePath: e, // 要上传的文件路径

name: 'file', // 文件对应的 key,服务器通过这个 key 获取文件内容

formData: {

'user': 'test' // 其他额外的 form data

},

success: (uploadFileRes) => {

console.log('上传成功', uploadFileRes.data);

uni.showToast({

title: '上传成功',

icon: 'success'

});

},

fail: (err) => {

console.error('上传失败', err);

uni.showToast({

title: '上传失败',

icon: 'none'

});

}

});

// 监听上传进度变化

uploadTask.onProgressUpdate((res) => {

this.uploadProgress = res.progress;

console.log(`上传进度:${res.progress}%`);

});

},

相关推荐
小高007几秒前
🔥「从零到一」我用 Node BFF 手撸一个 Vue3 SSR 项目(附源码)
前端·javascript·vue.js
superman超哥2 分钟前
Rust Rc与Arc的引用计数机制:共享所有权的两种实现
开发语言·后端·rust·编程语言·rust rc与arc·引用计数机制·共享所有权
SailingCoder3 分钟前
AI 流式对话该怎么做?SSE、fetch、axios 一次讲清楚
前端·javascript·人工智能·ai·node.js
提笔忘字的帝国4 分钟前
【2026版】macOS 使用 Homebrew 快速安装 Java 21 教程
java·开发语言·macos
半壶清水4 分钟前
【开源免费】使用 Python + Whisper + PyDub 自动切割长音频文件
开发语言·python·语言模型·开源·whisper
ghostwritten4 分钟前
go.mod 与go.sum有什么区别?
开发语言·后端·golang
hxjhnct7 分钟前
Vue 实现多行文本“展开收起”
前端·javascript·vue.js
百锦再9 分钟前
Vue大屏开发全流程及技术细节详解
前端·javascript·vue.js·微信小程序·小程序·架构·ecmascript
抹香鲸之海9 分钟前
Easyexcel 多级横向合并表头
java·开发语言·windows
麻瓜呀10 分钟前
vue2之el-table表格多选改单选
javascript·vue.js·elementui