java传送视频保留在本地_springboot接收别人上传的本地视频实例代码

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配置

org.springframework.boot

spring-boot-configuration-processor

true

commons-fileupload

commons-fileupload

1.2.2

总结

以上所述是小编给大家介绍的springboot接收别人上传的本地视频,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对脚本之家网站的支持!

125分50秒---162.81M---LabView01---第10章数据的显示.wmv---F:/Resource/video/硬件/AltiumDesigner/LabView01-第10章数据的显示.wmv 92分2秒---143.46M---LabView02---第11章文件的IO及保存.wmv---F:/Resource/video/硬件/AltiumDesigner/LabView02-第11章文件的IO及保存.wmv 37分22秒---58.09M---LabView03---第12章LabVIEW的通信.wmv---F:/Resource/video/硬件/AltiumDesigner/LabView03-第12章LabVIEW的通信.wmv 9分58秒---21.2M---LabView04---第13章LabVIEW与其它软件的连接.wmv---F:/Resource/video/硬件/AltiumDesigner/LabView04-第13章LabVIEW与其它软件的连接.wmv 4分45秒---9.99M---LabView05---第14章LabVIEW中子VI的设置及调用.wmv---F:/Resource/video/硬件/AltiumDesigner/LabView05-第14章LabVIEW中子VI的设置及调用.wmv 34分30秒---61.03M---LabView06---第15章其它高级技巧.wmv---F:/Resource/video/硬件/AltiumDesigner/LabView06-第15章其它高级技巧.wmv 9分41秒---11.37M---LabView07---第2章第一个LabVIEW例子.wmv---F:/Resource/video/硬件/AltiumDesigner/LabView07-第2章第一个LabVIEW例子.wmv 86分58秒---140.25M---LabView08---第3章基本元素.wmv---F:/Resource/video/硬件/AltiumDesigner/LabView08-第3章基本元素.wmv 76分48秒---143.72M---LabView09---第4章程序结构.wmv---F:/Resource/video/硬件/AltiumDesigner/LabView09-第4章程序结构.wmv 5分46秒---14.67M---LabView10---第5章数据采集.wmv---F:/Resource/video/硬件/AltiumDesigner/LabView10-第5章数据采集.wmv 12分50秒---18.35M---LabView11---第6章数据传输及电脑接口.wmv---F:/Resource/video/硬件/AltiumDesigner/LabView11-第6章数据传输及电脑接口.wmv 59分57秒---87.83M---LabView12---第7章数据的分析及处理.wmv---F:/Resource/video/硬件/AltiumDesigner/LabView12-第7章数据的分析及处理.wmv 42分4秒---61.02M---LabView13---第8章LabVIEW的信号调理.wmv---F:/Resource/video/硬件/AltiumDesigner/LabView13-第8章LabVIEW的信号调理.wmv 132分19秒---178.86M---LabView14---第9章分析处理中数学计算.wmv---F:/Resource/video/硬件/AltiumDesigner/LabView14-第9章分析处理中数学计算.wmv
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值