当前位置: 首页 > news >正文

uniapp 一次性上传多条视频 u-upload accept=“video“ uni.chooseMedia uni.uploadFile

在这里插入图片描述

方式 一 部分安卓机 只能一条一条传视频

文档地址 uview 2.0 Upload 上传组件
html

<view class="formupload"><u-upload accept="video":fileList="fileList3" @afterRead="afterRead" @delete="deletePic" name="3" multiple:maxCount="9"></u-upload>
</view>

script

	// 删除图片deletePic(event) {this[`fileList${event.name}`].splice(event.index, 1)},// 新增图片 afterReadasync afterRead(event) {// 当设置 mutiple 为 true 时, file 为数组格式,否则为对象格式let lists = [].concat(event.file)let fileListLen = this[`fileList${event.name}`].length;lists.map((item) => {this[`fileList${event.name}`].push({...item,status: 'uploading',message: '上传中'})})for (let i = 0; i < lists.length; i++) {const result = await this.uploadFilePromise(event.name,lists[i].url);let item = this[`fileList${event.name}`][fileListLen]this[`fileList${event.name}`].splice(fileListLen, 1, Object.assign(item, {status: 'success',message: '',url: result}))fileListLen++}},uploadFilePromise(num,url) {return new Promise((resolve, reject) => {let a = uni.uploadFile({url: baseUrl + 'upload', // 上传图片视频的接口名filePath: url,name: 'file',header: {},formData: {file: url},success: (res) => {res.data = JSON.parse(res.data)if (res.data.code == 0) {setTimeout(() => {resolve(res.data.url)}, 1000)} else {uni.showToast({title: '上传失败',icon: 'none'});this[`fileList${num}`].pop()return}},fail: (error) => {uni.showToast({title: '上传失败',icon: 'none'});reject(error)}});})},

方式 二 可以一次性上传多条视频

文档地址 video
uni.chooseMedia
uni.uploadFile

html

	<view class="u-flex wrap"><image src="@/static/image/up.png" mode="" class="u-w-160 u-h-160 u-m-r-16 u-m-b-16" @click="upvideoFun" v-if="fileList3.length < 9"></image><view class="vibox" v-for="(item,i) in fileList3" :key="i"><video :src="item.url" class="viimg"></video><view class="vitext" @click="delFun(i)">  <text>x</text>  </view>	</view></view>

script

	// 上传视频upvideoFun(){let that = this;uni.chooseMedia({count: 9,mediaType: ['video'],sourceType: ['album', 'camera'],maxDuration: 30,camera: 'back',success(res) {let lists = [].concat(res.tempFiles);for (let i = 0; i < lists.length; i++) {uni.uploadFile({url: baseUrl + 'upload',filePath: lists[i].tempFilePath,name: 'file',formData: {},success: (resres) => {let data = JSON.parse(resres.data);that.fileList3.push({url:data.url});}});}}});},// 删除视频delFun(i){this.fileList3.splice(i, 1);},

css

.vibox{width: 80px;height: 80px;position: relative;border-radius: 2px;margin: 0 8px 8px 0;overflow: hidden;display: flex;flex-direction: row;.viimg{width: 80px;height: 80px;}.vitext{position: absolute;top: 0;right: 0;background-color: #373737;height: 14px;width: 14px;display: flex;border-bottom-left-radius: 100px;align-items: center;justify-content: center;z-index: 3;text{font-size: 10px;font-weight: normal;top: 0px;color: #ffffff;transform: translate(1px,-3px);}}}
http://www.lryc.cn/news/191797.html

相关文章:

  • CentOS7卸载硬盘报错:umount: /data: target is busy.
  • Chrome插件精选 — 鼠标手势插件
  • JMeter分布式
  • [华为杯研究生创新赛 2023] 初赛 REV WP
  • C++中resize和reserve
  • 【面试经典150 | 哈希表】存在重复元素 II
  • Intellij 安装配置 lombok
  • Chrome插件精选 — 暗色主题插件
  • PXE解决uefi安装centos6黑屏问题
  • Feign 调用为何POST不支持同时传入多个SpringQueryMap对象,但是GET方法就支持?
  • RISC-V 特权级架构
  • 目录启示:PHP 与命名空间的声明
  • D. Divide and Equalize--Codeforces Round 903 (Div. 3)
  • 保姆式教程:MAC安装Android studio(包括安装JDK,Android SDK),解决gradle下载慢的问题
  • Ps:选区的布尔运算
  • PyTorch 深度学习之卷积神经网络(基础篇)Basic CNN(九)
  • torch实现Gated PixelCNN
  • 破局「二次创业」:合思的新解法
  • 第五章:TCP和UDP基本原理
  • 算法:动态规划的入门理解
  • 最新版nacos 2.2.3服务注册与发现版本依赖问题
  • 2023年中国合同能源管理行业研究报告
  • php以半小时为单位,输出指定的时间范围
  • Electron应用的 asar 打包 解压
  • 蓝桥等考Python组别十七级003
  • Redis概述和与SpringBoot的整合
  • Python 中的 round() 函数:实现精确的数值舍入操作
  • 在springboot中如何开启Bean数据校验
  • 【C语言好题系列三】
  • ElasticSearch搜索引擎:常用的存储mapping配置项 与 doc_values详细介绍