use of org.apache.commons.fileupload.FileUploadBase.IOFileUploadException in project JessMA by ldcsaa.
the class FileUploader method upload.
/** 执行上传
*
* @param request : {@link HttpServletRequest} 对象
* @param response : {@link HttpServletResponse} 对象
*
* @return : 成功:返回 {@link Result#SUCCESS} ,失败:返回其他结果,
* 失败原因通过 {@link FileUploader#getCause()} 获取
*
*/
public Result upload(HttpServletRequest request, HttpServletResponse response) {
reset();
String absolutePath = getAbsoluteSavePath(request);
if (absolutePath == null) {
cause = new FileNotFoundException(String.format("path '%s' not found or is not directory", savePath));
return Result.INVALID_SAVE_PATH;
}
ServletFileUpload sfu = getFileUploadComponent();
List<FileItemInfo> fiis = new ArrayList<FileItemInfo>();
List<FileItem> items = null;
Result result = Result.SUCCESS;
String encoding = servletHeaderencoding != null ? servletHeaderencoding : request.getCharacterEncoding();
FileNameGenerator fnGenerator = fileNameGenerator != null ? fileNameGenerator : DEFAULT_FILE_NAME_GENERATOR;
try {
items = (List<FileItem>) sfu.parseRequest(request);
} catch (FileUploadException e) {
cause = e;
if (e instanceof FileSizeLimitExceededException)
result = Result.FILE_SIZE_EXCEEDED;
else if (e instanceof SizeLimitExceededException)
result = Result.SIZE_EXCEEDED;
else if (e instanceof InvalidContentTypeException)
result = Result.INVALID_CONTENT_TYPE;
else if (e instanceof IOFileUploadException)
result = Result.FILE_UPLOAD_IO_EXCEPTION;
else
result = Result.OTHER_PARSE_REQUEST_EXCEPTION;
}
if (result == Result.SUCCESS) {
result = parseFileItems(items, fnGenerator, absolutePath, encoding, fiis);
if (result == Result.SUCCESS)
result = writeFiles(fiis);
}
return result;
}
Aggregations