前端和页面我就不写了,根据官网的demo写就行了http://www.uploadify.com/demos/
我只上传后台的代码
@RequestMapping("upload")
@ResponseBody
public String uploadManyFile(HttpServletRequest request)throws IllegalStateException, IOException{
//创建文件夹
String projectPath = request.getSession().getServletContext().getRealPath("image");//项目具体路径
File documentFile = new File(projectPath);
if(!documentFile.exists()){
documentFile.mkdir();
}
//创建一个通用的多部分解析器
CommonsMultipartResolver multipartResolver = new CommonsMultipartResolver(request.getSession().getServletContext());
if(multipartResolver.isMultipart(request)){
//转换成多部分request
MultipartHttpServletRequest req = (MultipartHttpServletRequest)request;
req.setCharacterEncoding("utf-8");
//取得request中的所有文件
Map<String, MultipartFile> fileMap = req.getFileMap();
Set<String> keySet = fileMap.keySet();
Iterator<String> iterator = keySet.iterator();
while(iterator.hasNext()){
MultipartFile file = fileMap.get(iterator.next());
//文件全名
String fileName = file.getOriginalFilename();
//如果名称不为“”,说明该文件存在,否则说明该文件不存在
if(!fileName.trim().equals("")){
//重命名上传后的文件名
String path = "C:\\Users\\Administrator\\Desktop\\新建文件夹\\ddd\\" + fileName;
file.transferTo(new File(path));
}
}
}
return "{\"returnCode\":1}";
}