springboot接收别人上传的本地视频实例代码
作者:qq_33931552 发布时间:2023-03-22 01:55:39
标签:spring,boot,本地视频,上传
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配置
#设置文件大小 srpingboot不设置会报错
spring.servlet.multipart.max-file-size : 10mb
spring.servlet.multipart.max-request-size : 100mb
#文件存放地址
file_address: D:\\image
pom配置
<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
0
投稿
猜你喜欢
- 我们都知道,当RecyclerView数据源更新后,还需要通过adapter调用对应的方法,从而让RecyclerView重新绘制页面本次也
- 前言在上一篇文章中讲完了SpringMVC的大部分知识,此篇文章中主要讲解 * 。上一篇文章🚩 * 的使用是非常普遍的。例如在 OA系统中通
- 1、导包基于maven<dependency> <groupId>com.fasterxml.jacks
- 本文实例讲述了Java使用Math.random()结合蒙特卡洛方法计算pi值。分享给大家供大家参考,具体如下:一、概述蒙特·卡罗方法(Mo
- 功能:解决web站点的登录,权限验证,授权等功能优点:在不影响站点业务代码,可以权限的授权与验证横切到业务中1、要添加的依赖<!--t
- Java for循环标签跳转到指定位置大家是否见过这种for循环,在for循环前加了个标记的:outerLoop:for (; ; ) {
- 先看代码public class TestDemo1 { public static void main(String[] ar
- 自从SEOTcs系统11月份24日更新了一下SEO得分算法以来,一直困扰我的一个问题出现了,java的数据job任务,在执行过程中会经常报以
- 一、前言最近写了个项目,前端还没写,需要部署到服务器给女朋友实现前端,可是不熟悉Linux的我,蹑手蹑脚,真的是每一步都是bug,可谓是步步
- 最近要做一个java web项目,因为页面不是很多,所以就没有前后端分离,前后端写在一起,这时候就用到thymeleaf了,以下是不动脑式的
- Java中List.of()和Arrays.asList()的区别及原因动手写一下,让自己更有印象1.Arrays.asList()可以插入
- 本文实例为大家分享了java导出csv格式文件的具体代码,供大家参考,具体内容如下导出csv格式文件的本质是导出以逗号为分隔的文本数据imp
- BeanDefinitionRegistryPostProcessor概述可以看到BeanDefinitionRegistryPostPro
- 场景需要判断,首字母是否是英文字母。有人说,那还不简单么,StringUtils.isAlpha() 就可以搞定。 笔者也是这么想的,结果却
- 现在有一张订单表t_stockorder,其拥有id、code、client_id、merchandise_id、merchandise_n
- 最近做一个需求,需求中的bean只用于生成一次json使用,所以想通过配置来动态的生成,查了一下,java还真有这个实现。java动态的生成
- 本文介绍了Spring Boot 开发REST接口最佳实践,分享给大家,具体如下:HTTP动词与SQL命令对应GET从服务器获取资源,可一个
- 打包与运行在项目开发完成之后,可以直接用IDEA将其打包成JAR包运行,也可以打包成WAR包运行以便在多服务器、多配置环境下运行。双击cle
- 合并有序数组的实现java版本:实例代码public class Merge {//合并有序数组 public static v
- 字段策略 0:”忽略判断”,1:”非 NULL 判断”),2:”非空判断”问题描述:当字段策略为 0 “忽略判断” 的时候,如果实体和数据库