提交 a5429e00 编写于 作者: 喷火的神灵's avatar 喷火的神灵 🎱

视频上传

上级 979714d5
此差异已折叠。
...@@ -30,6 +30,8 @@ ...@@ -30,6 +30,8 @@
"@vue/cli-service": "~5.0.0", "@vue/cli-service": "~5.0.0",
"eslint": "^7.32.0", "eslint": "^7.32.0",
"eslint-plugin-vue": "^8.0.3", "eslint-plugin-vue": "^8.0.3",
"vue-template-compiler": "^2.6.14" "vue-template-compiler": "^2.6.14",
"webpack": "^5.88.2",
"webpack-cli": "^5.1.4"
} }
} }
...@@ -78,7 +78,7 @@ export default { ...@@ -78,7 +78,7 @@ export default {
width: 250px; width: 250px;
overflow-y: auto; overflow-y: auto;
border: 0; border: 0;
background-image: linear-gradient(#fad7a1, #e96d71); background-image: linear-gradient(#FF9565, #FB2C4C);
} }
/deep/ #sidebar li ul { /deep/ #sidebar li ul {
background-color: transparent !important; background-color: transparent !important;
......
...@@ -332,6 +332,19 @@ export function uploadVideo(params, onUploadProgress) { ...@@ -332,6 +332,19 @@ export function uploadVideo(params, onUploadProgress) {
}) })
} }
// 上传封面
export function uploadCover(params, onUploadProgress) {
return request({
method: "post",
url: "/video/uploadCover",
data: params,
headers: {
'Content-Type': 'multipart/form-data'
},
onUploadProgress: onUploadProgress
})
}
// 上传视频信息 // 上传视频信息
export function uploadContent(params) { export function uploadContent(params) {
return request({ return request({
...@@ -342,6 +355,7 @@ export function uploadContent(params) { ...@@ -342,6 +355,7 @@ export function uploadContent(params) {
} }
// 获取视频页所有数量 // 获取视频页所有数量
export function LikeCount(params) { export function LikeCount(params) {
return request({ return request({
......
...@@ -37,19 +37,19 @@ ...@@ -37,19 +37,19 @@
class="upload-demo" class="upload-demo"
action="#" action="#"
list-type="picture-card" list-type="picture-card"
:auto-upload="false"
:multiple="false" :multiple="false"
accept=".jpg" accept=".jpg"
:limit="1" :limit="1"
:on-change="addFile" :on-change="addFile"
ref="files" ref="files"
:http-request="uploadCoverFile"
> >
<i slot="default" class="el-icon-plus"></i> <i slot="default" class="el-icon-plus"></i>
<div slot="file" slot-scope="{file}"> <div slot="file" slot-scope="{file}">
<img <img
class="el-upload-list__item-thumbnail" class="el-upload-list__item-thumbnail"
:src="video.videoImgUrl" alt="" :src="videoImgUrl" alt=""
> >
<span class="el-upload-list__item-actions"> <span class="el-upload-list__item-actions">
<span <span
...@@ -78,7 +78,7 @@ ...@@ -78,7 +78,7 @@
</el-upload> </el-upload>
<el-dialog :visible.sync="dialogVisible"> <el-dialog :visible.sync="dialogVisible">
<img width="100%" :src="video.videoImgUrl" alt=""> <img width="100%" :src="videoImgUrl" alt="">
</el-dialog> </el-dialog>
</div> </div>
<!-- 上传封面结束 --> <!-- 上传封面结束 -->
...@@ -143,6 +143,7 @@ ...@@ -143,6 +143,7 @@
import { import {
uploadVideo, // 上传视频 uploadVideo, // 上传视频
uploadContent, // 提交视频信息 uploadContent, // 提交视频信息
uploadCover, // 上传封面
} from "@/utils/option" } from "@/utils/option"
export default { export default {
name: "contribute", name: "contribute",
...@@ -203,21 +204,95 @@ export default { ...@@ -203,21 +204,95 @@ export default {
value: '', value: '',
/*视频分类*/ /*视频分类*/
/*上传封面*/ /*上传封面*/
dialogImageUrl: '', // dialogImageUrl: '',
dialogVisible: false, dialogVisible: false,
disabled: false, disabled: false,
/*上传封面*/ /*上传封面*/
videoImgUrl: "",
tags: "", tags: "",
input: '' input: ''
} }
}, },
methods: { methods: {
// 上传封面
uploadCoverFile(param) {
console.log(222)
const file = param.file;
let form = new FormData();
form.append("file", file);
uploadCover(form).then(res => {
if (res.success) {
this.video.videoImgUrl = res.data;
console.log(this.video.videoImgUrl)
}
})
},
// 上传给后台管理视频信息 // 上传给后台管理视频信息
uploadInformation() { uploadInformation() {
console.log(this.video); console.log(this.video);
if(this.video.title == "") {
this.$notify.error({
title: '',
message: "请输入标题",
position: 'bottom-right'
});
return;
}
if(this.video.description == "") {
this.$notify.error({
title: '',
message: "请描述内容",
position: 'bottom-right'
});
return;
}
if(this.video.videoImgUrl == "") {
this.$notify.error({
title: '',
message: "请上传封面",
position: 'bottom-right'
});
return;
}
if(this.video.videoSrcUrl == "") {
this.$notify.error({
title: '',
message: "请上传视频",
position: 'bottom-right'
});
return;
}
if(this.video.type == "") {
this.$notify.error({
title: '',
message: "请选择分类",
position: 'bottom-right'
});
return;
}
if(this.video.videoSrcUrl.length<=0) {
this.$notify.error({
title: '',
message: "请选择标签",
position: 'bottom-right'
});
return;
}
uploadContent(this.video).then(res => { uploadContent(this.video).then(res => {
if (res.success) { if (res.success) {
alert("成了") this.$notify({
title: '',
message: "投稿成功,请等待审核",
position: 'bottom-right',
type: "success"
});
} else {
this.$notify.error({
title: '',
message: res.message,
position: 'bottom-right'
});
} }
}) })
}, },
...@@ -235,10 +310,23 @@ export default { ...@@ -235,10 +310,23 @@ export default {
// } // }
}).then(res => { }).then(res => {
if (res.success) { if (res.success) {
alert("上传成功"); // this.$notify({
// title: '上传成功',
// message: res.message,
// position: 'bottom-right',
// type: "success"
// });
console.log(this.progress) console.log(this.progress)
this.video.userID = res.data.userID; this.video.userID = res.data.userID;
this.video.videoSrcUrl = res.data.videoSrcUrl; this.video.videoSrcUrl = res.data.videoSrcUrl;
} else {
this.$notify.error({
title: '',
message: res.message,
position: 'bottom-right'
});
location.reload();
} }
}) })
}, },
...@@ -246,15 +334,15 @@ export default { ...@@ -246,15 +334,15 @@ export default {
// 删除封面 // 删除封面
handleRemove(file) { handleRemove(file) {
this.$refs.files.handleRemove(file); this.$refs.files.handleRemove(file);
this.video.videoImgUrl = "" this.videoImgUrl = ""
// 需要和后端对接进行删除 // 需要和后端对接进行删除
}, },
addFile(file) { addFile(file) {
// 当上传之后 获取上传的路径 // 当上传之后 获取上传的路径
this.video.videoImgUrl = file.url; this.videoImgUrl = file.url;
}, },
handlePictureCardPreview(file) { handlePictureCardPreview(file) {
this.video.videoImgUrl = file.url; this.videoImgUrl = file.url;
this.dialogVisible = true; this.dialogVisible = true;
}, },
handleDownload(file) { handleDownload(file) {
......
...@@ -39,6 +39,7 @@ import java.io.*; ...@@ -39,6 +39,7 @@ import java.io.*;
import java.util.Arrays; import java.util.Arrays;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
import java.util.UUID;
@Slf4j @Slf4j
@RestController @RestController
...@@ -59,7 +60,7 @@ public class VideoUploadController { ...@@ -59,7 +60,7 @@ public class VideoUploadController {
//声明一个全局变量用于保存上传进度 //声明一个全局变量用于保存上传进度
private static double uploadProgress = 0; private static double uploadProgress = 0;
// 上传视频
@PostMapping("/upload") @PostMapping("/upload")
public RestBean<Object> uploadVideo(@AuthenticationPrincipal CurrentPrincipal principal, public RestBean<Object> uploadVideo(@AuthenticationPrincipal CurrentPrincipal principal,
@RequestParam("file") MultipartFile file) throws EncoderException, IOException { @RequestParam("file") MultipartFile file) throws EncoderException, IOException {
...@@ -67,20 +68,19 @@ public class VideoUploadController { ...@@ -67,20 +68,19 @@ public class VideoUploadController {
// 获取当事人id // 获取当事人id
Long id = principal.getUserID(); Long id = principal.getUserID();
log.debug("file{}", file); log.debug("file{}", file);
System.out.println(1111111);
if (file.isEmpty() && file.getOriginalFilename().split("\\.")[1] != "mp4") { if (file.isEmpty() && file.getOriginalFilename().split("\\.")[1] != "mp4") {
// 返回请求参数异常 // 返回请求参数异常
return RestBean.failure(ServiceCode.ERROR_BAD_REQUEST); return RestBean.failure(ServiceCode.ERROR_BAD_REQUEST);
} }
String fileName = id + "mp4"; UUID randomUUID = UUID.randomUUID();
String fileName = randomUUID + "mp4";
//上传图片 //上传图片
ApplicationHome applicationHome = new ApplicationHome(this.getClass()); ApplicationHome applicationHome = new ApplicationHome(this.getClass());
String pre = applicationHome.getDir().getParentFile().getParentFile().getAbsolutePath() + String pre = applicationHome.getDir().getParentFile().getParentFile().getAbsolutePath() +
"\\src\\main\\resources\\videos\\"; "\\src\\main\\resources\\videos\\";
String path = pre + fileName; String path = pre + fileName;
File file1 = new File(path); File file1 = new File(path);
System.out.println(1111111);
//获取文件总大小 //获取文件总大小
long fileSize = file.getSize(); long fileSize = file.getSize();
long uploadedBytes = 0; long uploadedBytes = 0;
...@@ -90,7 +90,6 @@ public class VideoUploadController { ...@@ -90,7 +90,6 @@ public class VideoUploadController {
byte[] buffer = new byte[1024]; byte[] buffer = new byte[1024];
int bytesRead; int bytesRead;
System.out.println(1111111);
while((bytesRead = inputStream.read(buffer)) != -1) { while((bytesRead = inputStream.read(buffer)) != -1) {
//写入文件 //写入文件
outputStream.write(buffer, 0, bytesRead); outputStream.write(buffer, 0, bytesRead);
...@@ -102,7 +101,6 @@ public class VideoUploadController { ...@@ -102,7 +101,6 @@ public class VideoUploadController {
System.out.println("上传进度: " + uploadProgress + "%"); System.out.println("上传进度: " + uploadProgress + "%");
} }
} }
System.out.println(1111111);
//获取视频信息 //获取视频信息
MultimediaObject instance = new MultimediaObject(file1); MultimediaObject instance = new MultimediaObject(file1);
MultimediaInfo result = instance.getInfo(); MultimediaInfo result = instance.getInfo();
...@@ -120,7 +118,6 @@ public class VideoUploadController { ...@@ -120,7 +118,6 @@ public class VideoUploadController {
//创建file对象 //创建file对象
File deleteFile = new File(filePath); File deleteFile = new File(filePath);
System.out.println(222222);
//检查文件是否存在 //检查文件是否存在
if (deleteFile.exists()) { if (deleteFile.exists()) {
//调用delete()方法删除文件 //调用delete()方法删除文件
...@@ -140,6 +137,38 @@ public class VideoUploadController { ...@@ -140,6 +137,38 @@ public class VideoUploadController {
return RestBean.success(map); return RestBean.success(map);
} }
// 上传封面
@PostMapping("/uploadCover")
public RestBean<Object> uploadFile(@RequestParam("file") MultipartFile file) {
System.out.println(11111);
String endpoint = "http://oss-cn-beijing.aliyuncs.com";
String accessKeyId = "LTAI5tGC4JwEZS3Yfymv5kbA";
String accessKeySecret = "j4s9H2eoHFOOcbxrCzlwV7zwTrBB4L";
String bucketName = "youbili-image";
//创建OSSClient实例
System.out.println(22222);
OSS ossClient = new OSSClientBuilder().build(endpoint, accessKeyId, accessKeySecret);
try {
//上传文件
String objectName = file.getOriginalFilename();//上传到OSS后的文件名
objectName = UUID.randomUUID()+objectName;
ossClient.putObject(bucketName, objectName, file.getInputStream());
//返回上传成功的消息
log.debug("objectName{}", objectName);
return RestBean.success(objectName);
} catch (Exception e) {
e.printStackTrace();
//返回上传失败的消息
return RestBean.failure(ServiceCode.ERROR_BAD_REQUEST);
} finally {
//关闭OSSClient
ossClient.shutdown();
}
}
// 上传信息
@PostMapping("/uploadContent") @PostMapping("/uploadContent")
public RestBean<Object> uploadContent(UploadContentDTO video) { public RestBean<Object> uploadContent(UploadContentDTO video) {
log.debug("video{}",video); log.debug("video{}",video);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册