use of ubic.gemma.web.util.upload.FailedMultipartHttpServletRequest in project Gemma by PavlidisLab.
the class FileUploadController method handleRequestInternal.
@Override
protected ModelAndView handleRequestInternal(HttpServletRequest request, HttpServletResponse response) {
if (!(request instanceof MultipartHttpServletRequest)) {
return null;
}
Map<String, Object> model = new HashMap<>();
if (request instanceof FailedMultipartHttpServletRequest) {
String errorMessage = ((FailedMultipartHttpServletRequest) request).getErrorMessage();
model.put("success", false);
model.put("error", errorMessage);
} else {
MultipartHttpServletRequest mrequest = (MultipartHttpServletRequest) request;
Map<String, MultipartFile> fileMap = mrequest.getFileMap();
if (fileMap.size() > 1) {
FileUploadController.log.error("Attempted to upload multiple files, returning error");
model.put("success", false);
model.put("error", "Sorry, can't upload more than one file at a time yet");
}
for (String key : fileMap.keySet()) {
MultipartFile multipartFile = fileMap.get(key);
File copiedFile = null;
try {
copiedFile = FileUploadUtil.copyUploadedFile(multipartFile, request);
FileUploadController.log.info("Uploaded file: " + copiedFile);
model.put("success", true);
model.put("localFile", StringEscapeUtils.escapeJava(copiedFile.getAbsolutePath()));
model.put("originalFile", multipartFile.getOriginalFilename());
model.put("size", multipartFile.getSize());
} catch (Exception e) {
FileUploadController.log.error("Error in upload: " + e.getMessage(), e);
model.put("success", false);
model.put("error", e.getMessage());
}
if (copiedFile == null) {
FileUploadController.log.error("Error in upload: unknown problem getting file");
model.put("success", false);
model.put("error", "unknown problem getting file");
}
}
}
return new ModelAndView(new JSONView("text/html; charset=utf-8"), model);
}
Aggregations