1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
|
package com.videobackend.controller; import java.io.file; import java.io.ioexception; import javax.servlet.http.httpservletrequest; import javax.servlet.http.httpservletresponse; import org.apache.log4j.logger; import org.springframework.beans.factory.annotation.autowired; import org.springframework.beans.factory.annotation.value; import org.springframework.stereotype.controller; import org.springframework.ui.model; import org.springframework.web.bind.annotation.requestmapping; import org.springframework.web.bind.annotation.requestmethod; import org.springframework.web.bind.annotation.requestparam; import org.springframework.web.bind.annotation.responsebody; import com.alibaba.fastjson.json; import com.alibaba.fastjson.jsonobject; import org.springframework.web.multipart.multipartfile; import com.ty.model.admintbl; import com.ty.model.rolepermissiontbl; import com.ty.service.permissionservice; import com.utils.constants; import com.utils.paramternullcheck; import com.utils.tointerface; import com.videobackend.model.video; import com.videobackend.model.videorecommend; @controller @requestmapping (value = "/videoinfo" ) public class videocontroller { /** * 调测日志记录器。 */ private static final logger debugger = logger.getlogger(videocontroller. class ); @autowired private permissionservice permissionservice; private static string file_address; @value ( "${file_address}" ) public void setfile_address(string file_address) { file_address = file_address; } /** * * @param request * @param response * @param model * @param video * @param admintabl * @return * @throws ioexception * @throws illegalstateexception */ @requestmapping (value = "/save_local_video" , method = requestmethod.post) @responsebody public string save_local_video( @requestparam ( "file" ) multipartfile file, video video, admintbl admintabl) throws illegalstateexception, ioexception { jsonobject result = new jsonobject(); string[] args = { "admin_id" , "cover" , "createdtime" , "title" }; jsonobject nullcheck = paramternullcheck.getinstance().checknull(video, args); if (!file.isempty()) { //存放地址 string path = file_address; //如果父文件夹不存在 则创建文件夹 文件夹为path,视频名字file.getoriginalfilename() file filepath = new file(path, file.getoriginalfilename()); if (!filepath.getparentfile().exists()) { filepath.getparentfile().mkdirs(); } file fi = new file(path + file.separator + file.getoriginalfilename()); //下载到本地 file.transferto(fi); //获取绝对路径 string localaddress = fi.getabsolutepath(); debugger.info( "存入本地文件地址:" + localaddress); video.setlocaladdress(localaddress); //获取后缀名 string suffix= localaddress.substring(localaddress.lastindexof( "." ), localaddress.length()); debugger.info( "后缀名:" + suffix); video.setsuffix(suffix); if (nullcheck == null ) { // 查询该 用户是否有该权限 admintabl.seturl( "/videoinfo/save_local_video" ); rolepermissiontbl rpt = permissionservice.get_permission(admintabl); if (rpt != null ) { jsonobject param = null ; param = (jsonobject) json.tojson(video); debugger.info(param.tojsonstring()); // 调取接口 stringbuffer savelocalvideo = tointerface.interfaceutil( "/video/savelocalvideo" , param.tojsonstring(), "post" ); result.put( "savelocalvideo" , savelocalvideo); } else { result.put( "msg" , constants.no_auth); } } else { result = nullcheck; } } else { debugger.info( "缺少的参数key=======" + file.getname()); result.put( "msg" , constants.sys_paramter_missing); } return result.tojsonstring(); } } |
yml配置
1
2
3
4
5
|
#设置文件大小 srpingboot不设置会报错 spring.servlet.multipart.max-file-size : 10mb spring.servlet.multipart.max-request-size : 100mb #文件存放地址 file_address: d:\\image |
pom配置
1
2
3
4
5
6
7
8
9
10
|
<dependency> <groupid>org.springframework.boot</groupid> <artifactid>spring-boot-configuration-processor</artifactid> <optional> true </optional> </dependency> <dependency> <groupid>commons-fileupload</groupid> <artifactid>commons-fileupload</artifactid> <version> 1.2 . 2 </version> </dependency> |
总结
以上所述是小编给大家介绍的springboot接收别人上传的本地视频,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对服务器之家网站的支持!
原文链接:https://blog.csdn.net/qq_33931552/article/details/81299235