@RequestMapping(value="/upload")
public @ResponseBody ActionResult upload(@RequestParam(value="directory", required=false) String directory,
@RequestParam(value="image") MultipartFile multipartFile, HttpServletRequest request){
ActionResult result = new ActionResult();
String fileName = null;
if(StringUtils.isNotEmpty(directory)){
if(!mediaFileService.isDirectory(directory)){
result.setError(message(request, "error.directory"));
}else{
if(multipartFile.isEmpty()){
result.setError(message(request, "error.file"));
}else{
String originalName = multipartFile.getOriginalFilename();
fileName = FilenameUtils.getName(originalName);
String fileExt = FilenameUtils.getExtension(originalName);
long fileSize = multipartFile.getSize();
if(fileName==null || fileName.length()<3 || fileName.length()>255){
result.setError(message(request, "error.filename"));
}else if(fileSize > getSettingService().getEnvironment().getProperty("fileUpload.maxSize", Long.class)){
result.setError(message(request, "error.fileSize"));
}else if(!FileFilters.MEDIA_TYPES.contains(fileExt.toLowerCase())){
result.setError(message(request, "error.fileType"));
}
}
}
}else{
result.setError(message(request, "error.directory"));
}
if(!UserPermissions.canModify("common/filemanager")){
result.setError(message(request, "error.permission"));
}
if(result.getError()==null){
if(mediaFileService.upload(multipartFile, PathUtils.ensureEndingFileSeparator(directory)+fileName)){
result.setSuccess(message(request, "text.uploaded"));
}else{
result.setError(message(request, "error.uploaded"));
}
}
return result;
}