文件上传

protected Map<String, String> getMultiParamterMap(HttpServletRequest request,
final List<FileItem> fileList) throws FileUploadException {
Map<String, String> param = new TreeMap<String, String>();
FileItemFactory factory = new DiskFileItemFactory();
ServletFileUpload upload = new ServletFileUpload(factory);
upload.setFileSizeMax(10 * (1 << 20));
List<FileItem> items = null;
try {
items = upload.parseRequest(request);
} catch (Exception e) {
throw new LeagException("att_too_large");
}
for (int i = 0; i < items.size(); i++) {
FileItem item = items.get(i);
if (item.isFormField()) {
try {
param.put(item.getFieldName(), item.getString("utf-8"));
} catch (UnsupportedEncodingException e) {
}
} else if (StringUtils.isNotEmpty(item.getName())) {
fileList.add(item);
}
}
return param;
}

你可能感兴趣的:(文件上传)