webuploader上传大文件后台java怎么接收
3个回答
展开全部
if(request.getHeader("content-type")!=null&&"application/x-www-form-urlencoded".equals(request.getHeader("content-type"))){
return null;
//将请求转换成MultipartHttpServletRequest
MultipartHttpServletRequest mRequest=(MultipartHttpServletRequest)request;
Enumeration<String> ps = mRequest.getParameterNames();
while(ps.hasMoreElements()){
String hname = ps.nextElement();
System.out.println(hname);
System.out.println(mRequest.getParameter(hname));
}
//获值
String value= mRequest.getParameter("key"); //获取单个数据的时候,取key值
Iterator<String> fns=mRequest.getFileNames();//获取上传的文件列表
while(fns.hasNext()){
String s =fns.next();
MultipartFile mFile = mRequest.getFile(s);
if(mFile.isEmpty()){
map.put("error", "message");
}else{
String basePath=Constant.BASEPICUPLOADPATH;
String dPath= Constant.SDF_PARAM.format(new Date());
File dir = new File(basePath+dPath);
if(!dir.exists()){
dir.mkdirs();
}
String originFileName=mFile.getOriginalFilename();
String suffix=originFileName.split("\\.")[originFileName.split("\\.").length-1];
String base64Name=UUID.randomUUID().toString();
File file = new File(basePath+dPath,base64Name+"."+suffix);
try {
FileUtils.copyInputStreamToFile(mFile.getInputStream(),file);//存储文件
} catch (IOException e) {
e.printStackTrace();
}
}
}
//最近刚好在做这方面的,希望能解决你的问题
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询