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

接口上传视频和oss直传视频到阿里云组件

在这里插入图片描述

接口视频上传

<template><div class="component-upload-video"><el-uploadclass="avatar-uploader":action="uploadImgUrl":on-progress="uploadVideoProcess":on-success="handleUploadSuccess":limit="limit":file-list="fileList":before-upload="handleBeforeUpload":show-file-list="false":headers="headers"ref="uploadRef"><videov-if="videoForm.showVideoPath && !videoFlag":src="videoForm.showVideoPath"class="avatar video-avatar"controls="controls">您的浏览器不支持视频播放</video><!-- //i标签是上传前的那个+上传后隐藏 --><iv-else-if="!videoForm.showVideoPath && !videoFlag"class="el-icon-plus avatar-uploader-icon"></i><el-progressv-if="videoFlag == true"type="circle":percentage="videoUploadPercent"style="margin-top: 7px"></el-progress></el-upload><el-buttonv-if="isShowBtn && videoForm.showVideoPath"class="mt-20"plainround@click="handleDelete"size="small"type="primary">重新上传<i class="el-icon-upload el-icon--right"></i></el-button></div>
</template><script>
import { getToken } from "@/utils/auth";export default {props: {value: [String, Object, Array],// 图片数量限制limit: {type: Number,default: 5,},// 大小限制(MB)fileSize: {type: Number,default: 50,},// 序号indexValue: {type: Number,default: null,},// 文件类型, 例如['video/avi', 'video/wmv', 'video/rmvb']fileType: {type: Array,default: () => ["video/mp4", "video/ogg", "video/flv"],},// 是否显示提示isShowTip: {type: Boolean,default: false,},// 是否显示进度条isShowUploadVideo: {type: Boolean,default: false,},// 是否显示重新上传按钮isShowBtn: {type: Boolean,default: true,},},data() {return {number: 0,dialogVisible: false,hideUpload: false,uploadImgUrl: process.env.VUE_APP_BASE_API + "/file/upload", // 上传的服务器地址headers: {Authorization: "Bearer " + getToken(),},fileList: [],videoForm: {showVideoPath: "", //回显的变量},duration: 0, //时长秒videoFlag: false,videoUploadPercent: 0,};},watch: {value: {handler(val) {if (val) {this.videoForm.showVideoPath = val;// 首先将值转为数组const list = Array.isArray(val) ? val : this.value.split(",");// 然后将数组转为对象数组this.fileList = list.map((item) => {if (typeof item === "string") {item = { name: item, url: item };}return item;});} else {this.fileList = [];return [];}},deep: true,immediate: true,},},computed: {// 是否显示提示showTip() {return this.isShowTip && (this.fileType || this.fileSize);},},methods: {// 上传成功回调handleUploadSuccess(res) {this.isShowUploadVideo = true;this.videoFlag = false;// this.videoUploadPercent = 0;console.log("handleUploadSuccess");//后台上传数据if (res.code == 200) {this.videoForm.showVideoPath = res.data.url; //上传成功后端返回视频地址 回显// var audioElement = new Audio(url);this.$emit("input", res.data.url, this.duration);this.$modal.msgSuccess("上传成功!");} else {this.$message.error("上传失败!");}},// 上传前loading加载handleBeforeUpload(file) {var url = URL.createObjectURL(file);var audioElement = new Audio(url);var time;var that = this;audioElement.addEventListener("loadedmetadata", function () {time = audioElement.duration; //时长为秒that.duration = time;});var fileSize = file.size / 1024 / 1024 < this.fileSize; //控制大小  修改50的值即可if (["video/mp4"].indexOf(file.type) == -1 //控制格式) {this.$modal.msgError(`文件格式不正确, 请上传${this.fileType.join("/")}视频格式文件!`);return false;}if (!fileSize) {this.$modal.msgError(`上传视频大小不能超过 ${this.fileSize} MB!`);return false;}},//进度条--------uploadVideoProcess(event, file, fileList) {//注意在data中添加对应的变量名this.videoFlag = true;console.log(file, "file", file.percentage);this.videoUploadPercent = file.percentage.toFixed(0) * 1;},// 文件个数超出handleExceed() {this.$modal.msgError(`上传视频数量不能超过 ${this.limit} 个!`);},// 上传失败handleUploadError() {this.$modal.msgError("上传视频失败,请重试");this.$modal.closeLoading();},handleDelete() {this.videoFlag = false;// 清除已上传的文件this.$refs.uploadRef.clearFiles();// 在这里可以执行其他删除操作,例如将视频地址重置为nullthis.videoForm.showVideoPath = "";},},
};
</script><style scoped lang="scss">
// .el-upload--picture-card 控制加号部分
::v-deep.hideUpload .el-upload--picture-card {display: none;
}::v-deep .el-upload--picture-card {width: 104px;height: 104px;line-height: 104px;
}::v-deep .el-upload-list--picture-card .el-upload-list__item {width: 104px;height: 104px;
}.avatar-uploader-icon {border: 1px dashed #d9d9d9 !important;
}.avatar-uploader .el-upload {border: 1px dashed #d9d9d9 !important;border-radius: 6px !important;position: relative !important;overflow: hidden !important;
}.avatar-uploader .el-upload:hover {border: 1px dashed #d9d9d9 !important;border-color: #409eff;
}.avatar-uploader-icon {font-size: 28px;color: #8c939d;width: 300px;height: 178px;line-height: 178px;text-align: center;
}.avatar {width: 300px;height: 178px;display: block;
}
</style>

oss直传视频到阿里云组件

<template><div class="component-upload-image"><el-uploadaction="":http-request="beforeUpload"class="avatar-uploader":limit="limit":on-error="handleUploadError":on-exceed="handleExceed"name="file":show-file-list="false":file-list="fileList"ref="uploadRef"><videov-if="videoForm.showVideoPath && !videoFlag":src="videoForm.showVideoPath"class="avatar video-avatar"controls="controls">您的浏览器不支持视频播放</video><!-- //i标签是上传前的那个+上传后隐藏 --><iv-else-if="!videoForm.showVideoPath && !videoFlag"class="el-icon-plus avatar-uploader-icon"></i><el-progressv-if="videoFlag == true"type="circle":percentage="videoUploadPercent"style="margin-top: 7px"></el-progress></el-upload><el-buttonv-if="isShowBtn && videoForm.showVideoPath"class="mt-20"plainround@click="handleDelete"size="small"type="primary">重新上传<i class="el-icon-upload el-icon--right"></i></el-button></div>
</template><script>
import { getOssParameter } from "./oss";export default {props: {value: [String, Object, Array],// 图片数量限制limit: {type: Number,default: 1,},// 大小限制(MB)fileSize: {type: Number,default: 5120,},fileType: {type: Array,default: () => ["video/*"],},// 是否显示提示isShowTip: {type: Boolean,default: true,},// 是否显示进度条isShowUploadVideo: {type: Boolean,default: false,},// 是否显示重新上传按钮isShowBtn: {type: Boolean,default: true,},},data() {return {dialogImageUrl: "",dialogVisible: false,hideUpload: false,baseUrl: process.env.VUE_APP_BASE_API,uploadImgUrl: process.env.VUE_APP_BASE_API + "/file/upload", // 上传的图片服务器地址fileList: [],videoForm: {showVideoPath: "", //回显的变量},videoFlag: false,videoUploadPercent: 0,isCancel: false,};},watch: {value: {handler(val) {if (val) {this.videoForm.showVideoPath = val;// 首先将值转为数组const list = Array.isArray(val) ? val : this.value.split(",");// 然后将数组转为对象数组this.fileList = list.map((item) => {if (typeof item === "string") {item = { name: item, url: item };}return item;});} else {this.fileList = [];return [];}},deep: true,immediate: true,},},computed: {// 是否显示提示showTip() {return this.isShowTip && (this.fileType || this.fileSize);},},methods: {//自定义上传方法..Upload(file, data) {let OSS = require("ali-oss");let client = new OSS({region: data.region,accessKeyId: data.accessKeyId,accessKeySecret: data.accessKeySecret,bucket: data.bucket,});// let cdnUrl = data.cdnUrl;let cdnUrl = "https://cdn-learning.cscec83.cn/";this.isCancel = false;//判断扩展名const tmpcnt = file.file.name.lastIndexOf(".");const exname = file.file.name.substring(tmpcnt + 1);//  配置路径以及文件名称const fileName = file.file.uid + "." + exname;const progress = (p, _checkpoint) => {this.videoFlag = true;this.videoUploadPercent = Number((Number(p) * 100).toFixed(1));console.log(this.isCancel);if (this.isCancel) {client.cancel();}};client.multipartUpload(fileName, file.file, {progress,// 设置并发上传的分片数量。// parallel: 4,// 设置分片大小。默认值为1 MB,最小值为100 KB。partSize: 5 * 1024 * 1024,}).then((res) => {console.log(res, "res");this.videoFlag = false;if (res.name) {this.videoForm.showVideoPath = cdnUrl + res.name;console.log(this.videoForm.showVideoPath, "fileUrl");this.$emit("input", this.videoForm.showVideoPath, this.duration);// this.loading.close();} else {this.$modal.msgError("上传视频失败,请重试");// this.loading.close();this.handleDelete();}}).catch((err) => {console.log(err);if (err.name == "cancel") {this.$message("上传取消");} else {this.$modal.msgError(err);}this.handleDelete();});},handleDelete() {this.isCancel = true;this.videoFlag = false;this.$refs.uploadRef.clearFiles();this.duration = 0;this.videoForm.showVideoPath = "";this.$emit("input", this.videoForm.showVideoPath, this.duration);// 清除已上传的文件},// 上传前loading加载beforeUpload(file) {var fileSize = file.file.size / 1024 / 1024 < this.fileSize; //控制大小  修改50的值即可console.log(file.file.type);if (this.fileType.indexOf(file.file.type) == -1 //控制格式) {this.$modal.msgError(`文件格式不正确, 请上传${this.fileType.join("/")}视频格式文件!`);return false;}if (!fileSize) {this.$modal.msgError(`上传视频大小不能超过 ${this.fileSize} MB!`);return false;}var url = URL.createObjectURL(file.file);var audioElement = new Audio(url);var time;var that = this;audioElement.addEventListener("loadedmetadata", function () {time = audioElement.duration; //时长为秒that.duration = time;});// this.loading = this.$loading({//   lock: true,//   text: "上传中",//   background: "rgba(0, 0, 0, 0.7)",// });getOssParameter().then((res) => {if (res.code == 200) {this.Upload(file, res.data);}});},// 文件个数超出handleExceed() {this.$message.error(`上传文件数量不能超过 ${this.limit} 个!`);},// 上传失败handleUploadError() {this.$modal.msgError("上传失败,请重试");// this.loading.close();},uploadCancel() {this.isCancel = true;},},
};
</script>
<style scoped lang="scss">
// .el-upload--picture-card 控制加号部分
::v-deep.hideUpload .el-upload--picture-card {display: none;
}::v-deep .el-upload--picture-card {width: 104px;height: 104px;line-height: 104px;
}::v-deep .el-upload-list--picture-card .el-upload-list__item {width: 104px;height: 104px;
}.avatar-uploader-icon {border: 1px dashed #d9d9d9 !important;
}.avatar-uploader .el-upload {border: 1px dashed #d9d9d9 !important;border-radius: 6px !important;position: relative !important;overflow: hidden !important;
}.avatar-uploader .el-upload:hover {border: 1px dashed #d9d9d9 !important;border-color: #409eff;
}.avatar-uploader-icon {font-size: 28px;color: #8c939d;width: 300px;height: 178px;line-height: 178px;text-align: center;
}.avatar {width: 300px;height: 178px;display: block;
}
</style>

相关文章:

接口上传视频和oss直传视频到阿里云组件

接口视频上传 <template><div class"component-upload-video"><el-uploadclass"avatar-uploader":action"uploadImgUrl":on-progress"uploadVideoProcess":on-success"handleUploadSuccess":limit"lim…...

Arcgis 地图制作

地图如下,不同历史时期&#xff1a;...

【每日一题1121】python校招笔试题、面试题

1、Python字符串不是通过NUL或者’\0’来结束的 C语言中字符串使用’\0’作为结束符&#xff0c;以防止越界。但是在python中&#xff0c;字符串值只包含所定义的东西。 2、执行以下程序&#xff0c;输出结果为&#xff08;&#xff09; class Base(object):count 0def __in…...

Spring Boot + Vue 基于 RSA 的用户身份认证加密机制实现

Spring Boot Vue 基于 RSA 的用户身份认证加密机制实现 什么是RSA&#xff1f;安全需求介绍前后端交互流程前端使用 RSA 加密密码安装 jsencrypt库实现敏感信息加密 服务器端生成RSA的公私钥文件Windows环境 生成rsa的公私钥文件Linux环境 生成rsa的公私钥文件 后端代码实现返…...

Docker搭建有UI的私有镜像仓库

Docker搭建有UI的私有镜像仓库 一、使用这个docker-compose.yml文件&#xff1a; version: 3services:registry-ui:image: joxit/docker-registry-ui:2.5.7-debianrestart: alwaysports:- 81:80environment:- SINGLE_REGISTRYtrue- REGISTRY_TITLEAtt Docker Registry UI- DE…...

Qt打开文件对话框选择文件之后弹出两次

项目场景&#xff1a; 在 Qt 中&#xff0c;使用 ui 自动生成的 UI 文件会为每个控件自动生成一些默认的槽函数。如果您手动创建的槽函数名称与这些自动生成的槽函数名称相同&#xff0c;就会导致信号被多次连接&#xff0c;从而引发多次弹出文件对话框的问题。 原因分析&…...

【JAVA】正则表达式中的正向肯定预查

在Java中&#xff0c;正向肯定预查&#xff08;Positive Lookahead&#xff09;是一种正则表达式的高级特性&#xff0c;用于在匹配某个模式之前检查某个条件是否满足。正向肯定预查不会消耗字符&#xff0c;也就是说&#xff0c;它不会将匹配的字符从剩余的字符串中移除&#…...

django从入门到实战(一)——路由的编写规则与使用

Django 路由的编写规则与使用 在 Django 中&#xff0c;路由&#xff08;URLconf&#xff09;是将 URL 映射到视图函数的机制。它允许我们定义网站的 URL 结构&#xff0c;并将请求分发到相应的处理函数。以下是关于 Django 路由的定义规则及使用的详细介绍。 1. Django 的路…...

vue框架开发的前端项目,build和package的区别

在使用 Vue 框架开发前端项目时&#xff0c;build 和 package 是两个常见的操作&#xff0c;它们有不同的目的和作用。下面是它们的区别&#xff1a; 1. Build&#xff08;构建&#xff09; build 是将前端源代码&#xff08;如 Vue 组件、JavaScript 文件、CSS 样式等&#…...

视频智能分析软件LiteAIServer摄像机实时接入分析平台噪声监测算法介绍

在视频监控领域&#xff0c;噪声问题一直是一个令人头疼的难题。无论是低光环境、摄像机传感器的高灵敏度&#xff0c;还是编码压缩过程中的失真&#xff0c;都可能导致视频中出现噪声&#xff0c;从而影响监控画面的清晰度和准确性。这些噪声不仅降低了视频的可读性&#xff0…...

鸿蒙UI开发与部分布局

UI开发 1. 布局概述 1.1 开发流程 1.先确定开发流程 -> 2.分析页面元素构成 ->3.选用合适的布局容器组件 1.3 布局元素组成&#xff1a;盒模型 2.1 布局分类 2.1 线性布局 线性布局是开发中最常用、最基础的布局&#xff0c;通过线性容器Row和Column构建 2.1.1 线性布…...

redis的map底层数据结构 分别什么时候使用哈希表(Hash Table)和压缩列表(ZipList)

在Redis中&#xff0c;Hash数据类型的底层数据结构可以是压缩列表&#xff08;ZipList&#xff09;或者哈希表&#xff08;HashTable&#xff09;。这两种结构的使用取决于特定的条件&#xff1a; 1. **使用ZipList的条件**&#xff1a; - 当Hash中的数据项&#xff08;即f…...

css水平居中+垂直居中

display:“flex”,position: “absolute”,top:“50%”,left:“50%”,transform: ‘translate(-50%, -50%)’...

设计模式之 组合模式

组合模式&#xff08;Composite Pattern&#xff09;是一种结构型设计模式&#xff0c;它通过将对象组合成树形结构来表示“部分-整体”层次。组合模式允许客户端统一处理单个对象和对象集合。换句话说&#xff0c;组合模式让客户端可以像处理单个对象一样处理对象的集合&#…...

LCR 001 两数相除

一.题目&#xff1a; . - 力扣&#xff08;LeetCode&#xff09; 二.原始解法-超时&#xff1a; class Solution: def divide(self, a: int, b: int) -> int: # 1&#xff09;分析&#xff1a; # 除法计算&#xff0c;不能使用除法符号&#xff0c;可以理解为实现除法 # 除法…...

数据库、数据仓库、数据湖、数据中台、湖仓一体的概念和区别

数据库、数据仓库、数据湖、数据中台和湖仓一体是数据管理和分析领域的不同概念&#xff0c;各自有不同的特点和应用场景。以下是它们的主要区别&#xff1a; 1. 数据库&#xff08;Database&#xff09; 定义&#xff1a;结构化的数据存储系统&#xff0c;用于高效地存储、检…...

vue 的生命周期函数

Vue 生命周期函数&#xff08;生命周期钩子&#xff09;是 Vue 实例从创建到销毁过程中&#xff0c;不同阶段所触发的特定函数。理解这些生命周期函数对于开发 Vue 应用至关重要&#xff0c;因为它们让你在不同的生命周期阶段执行代码&#xff0c;比如数据初始化、DOM 渲染完成…...

单片机UART协议相关知识

概念 UART&#xff08;Universal Asynchronous Receiver/Transmitter&#xff0c;通用异步收发传输器&#xff09; 是一种 异步 串行 全双工 通信协议&#xff0c;用于设备一对一进行数据传输&#xff0c;只需要两根线&#xff08;TX&#xff0c;RX&#xff09;。 异步&…...

【操作系统不挂科】<CPU调度(13)>选择题(带答案与解析)

前言 大家好吖&#xff0c;欢迎来到 YY 滴 操作系统不挂科 系列 &#xff0c;热烈欢迎&#xff01; 本章主要内容面向接触过C的老铁 本博客主要内容&#xff0c;收纳了一部门基本的操作系统题目&#xff0c;供yy应对期中考试复习。大家可以参考 本章为选择题题库&#xff0c;试…...

OpenCV笔记:图像去噪对比

图像去噪对比 1. 均值滤波&#xff08;Mean Filtering&#xff09; 方法&#xff1a;用像素周围的像素平均值替换每个像素值。适用场景&#xff1a;适用于去除随机噪声&#xff0c;如在不强调图像细节的场景中&#xff0c;如果图像细节较多时&#xff0c;可能会导致图像模糊。…...

业务系统对接大模型的基础方案:架构设计与关键步骤

业务系统对接大模型&#xff1a;架构设计与关键步骤 在当今数字化转型的浪潮中&#xff0c;大语言模型&#xff08;LLM&#xff09;已成为企业提升业务效率和创新能力的关键技术之一。将大模型集成到业务系统中&#xff0c;不仅可以优化用户体验&#xff0c;还能为业务决策提供…...

iOS 26 携众系统重磅更新,但“苹果智能”仍与国行无缘

美国西海岸的夏天&#xff0c;再次被苹果点燃。一年一度的全球开发者大会 WWDC25 如期而至&#xff0c;这不仅是开发者的盛宴&#xff0c;更是全球数亿苹果用户翘首以盼的科技春晚。今年&#xff0c;苹果依旧为我们带来了全家桶式的系统更新&#xff0c;包括 iOS 26、iPadOS 26…...

调用支付宝接口响应40004 SYSTEM_ERROR问题排查

在对接支付宝API的时候&#xff0c;遇到了一些问题&#xff0c;记录一下排查过程。 Body:{"datadigital_fincloud_generalsaas_face_certify_initialize_response":{"msg":"Business Failed","code":"40004","sub_msg…...

Python爬虫实战:研究feedparser库相关技术

1. 引言 1.1 研究背景与意义 在当今信息爆炸的时代,互联网上存在着海量的信息资源。RSS(Really Simple Syndication)作为一种标准化的信息聚合技术,被广泛用于网站内容的发布和订阅。通过 RSS,用户可以方便地获取网站更新的内容,而无需频繁访问各个网站。 然而,互联网…...

UDP(Echoserver)

网络命令 Ping 命令 检测网络是否连通 使用方法: ping -c 次数 网址ping -c 3 www.baidu.comnetstat 命令 netstat 是一个用来查看网络状态的重要工具. 语法&#xff1a;netstat [选项] 功能&#xff1a;查看网络状态 常用选项&#xff1a; n 拒绝显示别名&#…...

【大模型RAG】Docker 一键部署 Milvus 完整攻略

本文概要 Milvus 2.5 Stand-alone 版可通过 Docker 在几分钟内完成安装&#xff1b;只需暴露 19530&#xff08;gRPC&#xff09;与 9091&#xff08;HTTP/WebUI&#xff09;两个端口&#xff0c;即可让本地电脑通过 PyMilvus 或浏览器访问远程 Linux 服务器上的 Milvus。下面…...

Leetcode 3577. Count the Number of Computer Unlocking Permutations

Leetcode 3577. Count the Number of Computer Unlocking Permutations 1. 解题思路2. 代码实现 题目链接&#xff1a;3577. Count the Number of Computer Unlocking Permutations 1. 解题思路 这一题其实就是一个脑筋急转弯&#xff0c;要想要能够将所有的电脑解锁&#x…...

蓝牙 BLE 扫描面试题大全(2):进阶面试题与实战演练

前文覆盖了 BLE 扫描的基础概念与经典问题蓝牙 BLE 扫描面试题大全(1)&#xff1a;从基础到实战的深度解析-CSDN博客&#xff0c;但实际面试中&#xff0c;企业更关注候选人对复杂场景的应对能力&#xff08;如多设备并发扫描、低功耗与高发现率的平衡&#xff09;和前沿技术的…...

ffmpeg(四):滤镜命令

FFmpeg 的滤镜命令是用于音视频处理中的强大工具&#xff0c;可以完成剪裁、缩放、加水印、调色、合成、旋转、模糊、叠加字幕等复杂的操作。其核心语法格式一般如下&#xff1a; ffmpeg -i input.mp4 -vf "滤镜参数" output.mp4或者带音频滤镜&#xff1a; ffmpeg…...

CMake 从 GitHub 下载第三方库并使用

有时我们希望直接使用 GitHub 上的开源库,而不想手动下载、编译和安装。 可以利用 CMake 提供的 FetchContent 模块来实现自动下载、构建和链接第三方库。 FetchContent 命令官方文档✅ 示例代码 我们将以 fmt 这个流行的格式化库为例,演示如何: 使用 FetchContent 从 GitH…...