@RequestMapping(“/upload2.do”)
//@ResponseBody
public String uploadFile2(@RequestParam(“file”) CommonsMultipartFile file,int flag,
HttpServletRequest request,HttpSession session,String pluginUrl,Integer pluginid) throws IOException {
//文件夹路径
String packPath = “”;
//文件路径
String path =”“;
// 定义解析器去解析request
CommonsMultipartResolver mutilpartResolver = new CommonsMultipartResolver(request.getSession().getServletContext());
//request如果是Multipart类型、
if (mutilpartResolver.isMultipart(request)) {
//强转成 MultipartHttpServletRequest
MultipartHttpServletRequest multiRequest = (MultipartHttpServletRequest) request;
//获取文件名
Iterator it = multiRequest.getFileNames();
while (it.hasNext()) {
//获取MultipartFile类型文件
MultipartFile fileDetail = multiRequest.getFile(it.next());
if (fileDetail != null) {
String fileName = fileDetail.getOriginalFilename();
String currentDate = DateFormatUtils.getCurrentDate();
String accountName = session.getAttribute(“accountName”).toString();
PlatformDevEnApply apply = this.pluginService.getPlatformDevEnApplyByAccountName(accountName);
String orgId = apply.getOrganizationuid();//应用商编码
//pluginUrl 为审核不通过的插件包所在地址,如果pluginUrl存在且不为空,那么将该插件删除,且将插件状态置为已删除
System.out.println(“pluginUrl ==” + pluginUrl);
if(pluginUrl != null && !”“.equals(pluginUrl) ){
String delFile = new StringBuffer(pluginUrl).append(File.separator).append(fileName).toString();
/* String delFile = pluginUrl + fileName;
*/ System.out.println(“delFile = ” + delFile);
//String del = "rm -rf "+delFile;
System.out.println("===========before RunTimeExec.runTimeExec=====");
/*RunTimeExec.runTimeExec(del);*/
DeleteFile.deleteFile(delFile);
System.out.println("===========before RunTimeExec.runTimeExec=====");
pluginService.delPluginMessageById(pluginid);
}
// path = "/usr/upload" + fileName;
/*packPath = new StringBuffer().append(File.separator).append("usr")
.append(File.separator).append("upload")
.append(File.separator).append(currentDate)
.append(File.separator).append(orgId).toString();*/
/* String fileName = "Upload" + fileDetail.getOriginalFilename();
path = "D:/" + fileName;*/
String type="";
if(flag==1){//插件
type="1111";
}else if(flag==2){//文件
type="1";
}else if(flag==3){//图片
type="111";
}else if(flag==4){//图标
type="11";
}
ConfigInfo configInfo = configInfoService.getConfigInfoByFunctionType(type);
path=configInfo.getPath();
path=new StringBuffer(path).append(File.separator).append(fileName).toString();
//path = new StringBuffer(packPath).append(File.separator).append(fileName).toString();
System.out.println("path : " + path);
/* File pack = new File(packPath);
if(!pack.exists() && !pack.isDirectory()){
System.out.println("package not exists");
pack.mkdirs();
System.out.println("package create true");
}
System.out.println("=====package exists====");*/
File localFile = new File(path);
//将上传文件写入到指定文件出、核心!
fileDetail.transferTo(localFile);
//非常重要、有了这个想做什么处理都可以
//fileDetail.getInputStream();
}
}
}
request.setAttribute("path", path);
return "/admin/plugManage/pluginUpLoad.html";
}