public static List> uploadFile(HttpServletRequest request,
String[] params, Map values) throws Exception {
List<Map<String, Object>> result = new ArrayList<Map<String, Object>>();
MultipartHttpServletRequest mRequest = (MultipartHttpServletRequest) request;
Map<String, MultipartFile> fileMap = mRequest.getFileMap();
String uploadDir ="D:/bmgl/doc/upload/image/"; //request.getSession().getServletContext().getRealPath("/")+ FileOperateUtil.UPLOADDIR;
Date d = new Date();
//System.out.println(d);
SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd");
String dateNowStr = sdf.format(d);
uploadDir +=dateNowStr;
uploadDir +="/";
//System.out.println("格式化后的日期:" + dateNowStr);
File file = new File(uploadDir);
if (!file.exists()) {
file.mkdir();
}
String fileName = null;
int i = 0;
for (Iterator<Map.Entry<String, MultipartFile>> it = fileMap.entrySet()
.iterator(); it.hasNext(); i++) {
Map.Entry<String, MultipartFile> entry = it.next();
MultipartFile mFile = entry.getValue();
fileName = mFile.getOriginalFilename();
if(fileName != null && !"".equals(fileName)){
String storeName = rename(fileName);
String noZipName = uploadDir + storeName;
// 上传成为压缩文件 后面的 noZipName替换为zipName
//String zipName = zipName(noZipName);
// ZipOutputStream outputStream = new ZipOutputStream(
//new BufferedOutputStream(new FileOutputStream(zipName)));
//outputStream.putNextEntry(new ZipEntry(fileName));
//outputStream.setEncoding("GBK");
FileOutputStream out = new FileOutputStream(noZipName);
FileCopyUtils.copy(mFile.getInputStream(), out);
Map<String, Object> map = new HashMap<String, Object>();
// 固定参数值对
map.put(FileOperateUtil.REALNAME, fileName);
map.put(FileOperateUtil.STORENAME, storeName);
map.put(FileOperateUtil.SIZE, new File(noZipName).length());
map.put(FileOperateUtil.SUFFIX, "jpg");
map.put(FileOperateUtil.CONTENTTYPE, "application/octet-stream");
map.put(FileOperateUtil.CREATETIME, new Date());
map.put(FileOperateUtil.FULLPATHFILE, noZipName);
map.put("URL",uploadDir);
// 自定义参数值对
for (String param : params) {
map.put(param, values.get(param)[i]);
}
result.add(map);
}
}
return result;
}