Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
代码敲不队
YoubiliProject
提交
a5429e00
Y
YoubiliProject
项目概览
代码敲不队
/
YoubiliProject
通知
7
Star
1
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
Y
YoubiliProject
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
a5429e00
编写于
7月 22, 2023
作者:
喷火的神灵
🎱
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
视频上传
上级
979714d5
变更
6
展开全部
隐藏空白更改
内联
并排
Showing
6 changed file
with
555 addition
and
43 deletion
+555
-43
YouBili_front/package-lock.json
YouBili_front/package-lock.json
+404
-25
YouBili_front/package.json
YouBili_front/package.json
+3
-1
YouBili_front/src/components/sidebar.vue
YouBili_front/src/components/sidebar.vue
+1
-1
YouBili_front/src/utils/option.js
YouBili_front/src/utils/option.js
+14
-0
YouBili_front/src/views/contribute/contribute.vue
YouBili_front/src/views/contribute/contribute.vue
+97
-9
youbili-project-backend/src/main/java/cn/tedu/youbiliprojectbackend/modules/video/uplaod/controller/VideoUploadController.java
...odules/video/uplaod/controller/VideoUploadController.java
+36
-7
未找到文件。
YouBili_front/package-lock.json
浏览文件 @
a5429e00
此差异已折叠。
点击以展开。
YouBili_front/package.json
浏览文件 @
a5429e00
...
...
@@ -30,6 +30,8 @@
"@vue/cli-service"
:
"~5.0.0"
,
"eslint"
:
"^7.32.0"
,
"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"
}
}
YouBili_front/src/components/sidebar.vue
浏览文件 @
a5429e00
...
...
@@ -78,7 +78,7 @@ export default {
width
:
250px
;
overflow-y
:
auto
;
border
:
0
;
background-image
:
linear-gradient
(
#
fad7a1
,
#e96d71
);
background-image
:
linear-gradient
(
#
FF9565
,
#FB2C4C
);
}
/
deep
/
#sidebar
li
ul
{
background-color
:
transparent
!important
;
...
...
YouBili_front/src/utils/option.js
浏览文件 @
a5429e00
...
...
@@ -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
)
{
return
request
({
...
...
@@ -342,6 +355,7 @@ export function uploadContent(params) {
}
// 获取视频页所有数量
export
function
LikeCount
(
params
)
{
return
request
({
...
...
YouBili_front/src/views/contribute/contribute.vue
浏览文件 @
a5429e00
...
...
@@ -37,19 +37,19 @@
class=
"upload-demo"
action=
"#"
list-type=
"picture-card"
:auto-upload=
"false"
:multiple=
"false"
accept=
".jpg"
:limit=
"1"
:on-change=
"addFile"
ref=
"files"
:http-request=
"uploadCoverFile"
>
<i
slot=
"default"
class=
"el-icon-plus"
></i>
<div
slot=
"file"
slot-scope=
"
{file}">
<img
class=
"el-upload-list__item-thumbnail"
:src=
"video
.video
ImgUrl"
alt=
""
:src=
"videoImgUrl"
alt=
""
>
<span
class=
"el-upload-list__item-actions"
>
<span
...
...
@@ -78,7 +78,7 @@
</el-upload>
<el-dialog
:visible.sync=
"dialogVisible"
>
<img
width=
"100%"
:src=
"video
.video
ImgUrl"
alt=
""
>
<img
width=
"100%"
:src=
"videoImgUrl"
alt=
""
>
</el-dialog>
</div>
<!-- 上传封面结束 -->
...
...
@@ -143,6 +143,7 @@
import
{
uploadVideo
,
// 上传视频
uploadContent
,
// 提交视频信息
uploadCover
,
// 上传封面
}
from
"
@/utils/option
"
export
default
{
name
:
"
contribute
"
,
...
...
@@ -203,21 +204,95 @@ export default {
value
:
''
,
/*视频分类*/
/*上传封面*/
dialogImageUrl
:
''
,
//
dialogImageUrl: '',
dialogVisible
:
false
,
disabled
:
false
,
/*上传封面*/
videoImgUrl
:
""
,
tags
:
""
,
input
:
''
}
},
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
()
{
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
=>
{
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 {
// }
}).
then
(
res
=>
{
if
(
res
.
success
)
{
alert
(
"
上传成功
"
);
// this.$notify({
// title: '上传成功',
// message: res.message,
// position: 'bottom-right',
// type: "success"
// });
console
.
log
(
this
.
progress
)
this
.
video
.
userID
=
res
.
data
.
userID
;
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 {
// 删除封面
handleRemove
(
file
)
{
this
.
$refs
.
files
.
handleRemove
(
file
);
this
.
video
.
video
ImgUrl
=
""
this
.
videoImgUrl
=
""
// 需要和后端对接进行删除
},
addFile
(
file
)
{
// 当上传之后 获取上传的路径
this
.
video
.
video
ImgUrl
=
file
.
url
;
this
.
videoImgUrl
=
file
.
url
;
},
handlePictureCardPreview
(
file
)
{
this
.
video
.
video
ImgUrl
=
file
.
url
;
this
.
videoImgUrl
=
file
.
url
;
this
.
dialogVisible
=
true
;
},
handleDownload
(
file
)
{
...
...
youbili-project-backend/src/main/java/cn/tedu/youbiliprojectbackend/modules/video/uplaod/controller/VideoUploadController.java
浏览文件 @
a5429e00
...
...
@@ -39,6 +39,7 @@ import java.io.*;
import
java.util.Arrays
;
import
java.util.HashMap
;
import
java.util.Map
;
import
java.util.UUID
;
@Slf4j
@RestController
...
...
@@ -59,7 +60,7 @@ public class VideoUploadController {
//声明一个全局变量用于保存上传进度
private
static
double
uploadProgress
=
0
;
// 上传视频
@PostMapping
(
"/upload"
)
public
RestBean
<
Object
>
uploadVideo
(
@AuthenticationPrincipal
CurrentPrincipal
principal
,
@RequestParam
(
"file"
)
MultipartFile
file
)
throws
EncoderException
,
IOException
{
...
...
@@ -67,20 +68,19 @@ public class VideoUploadController {
// 获取当事人id
Long
id
=
principal
.
getUserID
();
log
.
debug
(
"file{}"
,
file
);
System
.
out
.
println
(
1111111
);
if
(
file
.
isEmpty
()
&&
file
.
getOriginalFilename
().
split
(
"\\."
)[
1
]
!=
"mp4"
)
{
// 返回请求参数异常
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
());
String
pre
=
applicationHome
.
getDir
().
getParentFile
().
getParentFile
().
getAbsolutePath
()
+
"\\src\\main\\resources\\videos\\"
;
String
path
=
pre
+
fileName
;
File
file1
=
new
File
(
path
);
System
.
out
.
println
(
1111111
);
//获取文件总大小
long
fileSize
=
file
.
getSize
();
long
uploadedBytes
=
0
;
...
...
@@ -90,7 +90,6 @@ public class VideoUploadController {
byte
[]
buffer
=
new
byte
[
1024
];
int
bytesRead
;
System
.
out
.
println
(
1111111
);
while
((
bytesRead
=
inputStream
.
read
(
buffer
))
!=
-
1
)
{
//写入文件
outputStream
.
write
(
buffer
,
0
,
bytesRead
);
...
...
@@ -102,7 +101,6 @@ public class VideoUploadController {
System
.
out
.
println
(
"上传进度: "
+
uploadProgress
+
"%"
);
}
}
System
.
out
.
println
(
1111111
);
//获取视频信息
MultimediaObject
instance
=
new
MultimediaObject
(
file1
);
MultimediaInfo
result
=
instance
.
getInfo
();
...
...
@@ -120,7 +118,6 @@ public class VideoUploadController {
//创建file对象
File
deleteFile
=
new
File
(
filePath
);
System
.
out
.
println
(
222222
);
//检查文件是否存在
if
(
deleteFile
.
exists
())
{
//调用delete()方法删除文件
...
...
@@ -140,6 +137,38 @@ public class VideoUploadController {
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"
)
public
RestBean
<
Object
>
uploadContent
(
UploadContentDTO
video
)
{
log
.
debug
(
"video{}"
,
video
);
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录