文件上传功能

@RequestMapping(value = "/uploadFile")
public void uploadPAD(@RequestParam("File") MultipartFile  filelist,HttpServletRequest request,HttpServletResponse response,HttpSession session) throws UnsupportedEncodingException{
request.setCharacterEncoding("utf-8");
response.setCharacterEncoding("utf-8");
response.setContentType("text/html");
String cinema_codes = request.getParameter("cinema_code");
JSONObject json = new JSONObject();
String returnInfo = "";
String uplaodFileName = null;//上传的文件全路径名
for(String cinema_code : cinema_codes.toString().split(",")){
if(StringUtils.isNotBlank(cinema_code)){
       String webPath =BaseUtil.readValue("CDN_MOVIE_PATH") + "version/"; 
// String webPath = "D:/version/";
webPath += cinema_code;
if(!filelist.isEmpty()){
try {
// 文件操作
try {
uplaodFileName = filelist.getOriginalFilename();
// 判断是否存在上传文件夹 无则创建
File dirPath = new File(webPath);
if (!dirPath.exists()) {
dirPath.mkdirs();
}

for (File file : dirPath.listFiles()) {
if (uplaodFileName.equals(file.getName())) {
FileUtil.deleteFile(file.toString());
}
}
// 创建文件
File uploadFile = new File(webPath +"/"+ uplaodFileName);

// Copy文件
FileCopyUtils.copy(filelist.getBytes(), uploadFile);
returnInfo = "上传成功 !";
} catch (Exception e) {
logger.error("uploadlist error", e);
returnInfo = "上传文件出错 !";
throw e;
}
// 操作日志
ExceptionUtils.addException(ExceptionUtils.USR_LOG,"上传版本文件成功", returnInfo, null, session,tms_OperationLogService);
} catch (Exception e) {
logger.error("uploadlist error", e);
if (returnInfo == null || "".equals(returnInfo)) {
returnInfo = "APK上传异常 !";
}
ExceptionUtils.addException(ExceptionUtils.EXCEPTION_LOG,"上传版本文件失败", returnInfo, e, session,tms_OperationLogService);
}
} else {
returnInfo = "文件没找到或无内容 , 请检查 !";
}
}
}

try {
json.put("returnInfo", returnInfo);
PrintWriter writer = response.getWriter();//将JSON数据返回给前台
writer.write(json.toString());
writer.close();
} catch (Exception e) {
}
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值