MultipartHttpServletRequest 文件上传
//单个文件上传
@RequestMapping(value = "/uploadFile/{path}", method = RequestMethod.POST)
@ResponseBody
public ReturnObj upload(@PathVariable("path") String _path, HttpServletRequest request,
HttpServletResponse response) {
MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request;
CommonsMultipartFile file = (CommonsMultipartFile) File("file");
// String name =
String realFileName = OriginalFilename();
System.out.println("文件名:" + realFileName);
String ctxPath = "";
if (StringUtils.isNotBlank(_path)) {
ctxPath =
} else {
ctxPath =
}
System.out.println("上传路径:" + ctxPath);
File dirPath = new File(ctxPath);
if (!ists()) {
dirPath.mkdir();
}
File uploadFile = new File(ctxPath + realFileName);
try {
} catch (IOException e) {getsavefilename
e.printStackTrace();
return new ReturnObj(ReturnObj.ERROR);
}
return new ReturnObj(ReturnObj.SUCCESS);
}
// 项目文件上传,多文件
@RequestMapping(value = "/uploadProFile", method = RequestMethod.POST)
public String uploadMore(HttpServletRequest request, HttpServletResponse response, Model model) {
String msg = "";
int _status = 0;
boolean hasFail = false;
StringBuffer sb = new StringBuffer();
String uploadType =
String proPath = "";
if
(StringUtils.Parameter("proPath"))) {
proPath = Parameter("proPath") + "/";
String warPath = proPath;
String jsPath = proPath
+ (Parameter("jsPath") == null ? "" : Parameter("jsPath"));
String ftlPath = proPath
+ (Parameter("ftlPath") == null ? "" : request
.getParameter("ftlPath"));
String imgPath = proPath
+ (Parameter("imgPath") == null ? "" : request
.
getParameter("imgPath"));
String version =
MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request;
Map<String, MultipartFile> fileMap = FileMap();
System.out.println("WAR上传路径:" + warPath);
System.out.println("JS上传路径:" + jsPath);
System.out.println("FTL上传路径:" + ftlPath);
System.out.println("IMG上传路径:" + imgPath);
createFileDir(jsPath, ftlPath, imgPath, warPath);
String fileName = null;
ProUpdate uploadRecord = null;
for (Map.Entry<String, MultipartFile> entity : Set()) {
MultipartFile mf = Value();
fileName = mf.getOriginalFilename();
if (StringUtils.isBlank(fileName)) {
continue;
}
File uploadFile = null;
if
(Extension(fileName).equalsIgnoreCase("js" )) {
if (StringUtils.isNotBlank(jsPath)) {
if (dsWith("/")) {
uploadFile = new File(jsPath + fileName);
} else
uploadFile = new File(jsPath + "/" + fileName);
}
} else if
(Extension(fileName).equalsIgnoreCase("ftl ")) {
if (StringUtils.isNotBlank(ftlPath)) {
if (dsWith("/")) {
uploadFile = new File(ftlPath + fileName);
} else
uploadFile = new File(ftlPath + "/" + fileName);
}
} else if
(Extension(fileName).toLower Case())) {
if (StringUtils.isNotBlank(imgPath)) {
if (dsWith("/")) {
uploadFile = new File(imgPath + fileName);
} else
uploadFile = new File(imgPath + "/" + fileName);
}
} else if
(Extension(fileName).equalsIgnoreCase("war ")) {
if (StringUtils.isNotBlank(warPath)) {
if (dsWith("/")) {
uploadFile = new File(warPath + fileName);
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。
发表评论