@RequestParam(value = "files[]", required = false) MultipartFile[] files) {
//The file upload plugin makes use of an Iframe Transport module for browsers like Microsoft Internet Explorer and Opera, which do not yet support XMLHTTPRequest file uploads.
response.setContentType("text/plain");
AjaxUploadResponse ajaxUploadResponse = new AjaxUploadResponse();
if (ArrayUtils.isEmpty(files)) {
return ajaxUploadResponse;
}
for (MultipartFile file : files) {
String filename = file.getOriginalFilename();
long size = file.getSize();
try {
String url = FileUploadUtils.upload(request, baseDir, file, allowedExtension, maxSize, true);
String deleteURL = "/ajaxUpload/delete?filename=" + URLEncoder.encode(url, Constants.ENCODING);
if (ImagesUtils.isImage(filename)) {
ajaxUploadResponse.add(filename, size, url, url, deleteURL);
} else {
ajaxUploadResponse.add(filename, size, url, deleteURL);
}
continue;
} catch (IOException e) {
LogUtils.logError("file upload error", e);
ajaxUploadResponse.add(filename, size, MessageUtils.message("upload.server.error"));
continue;
} catch (InvalidExtensionException e) {
ajaxUploadResponse.add(filename, size, MessageUtils.message("upload.not.allow.extension"));
continue;
} catch (FileUploadBase.FileSizeLimitExceededException e) {
ajaxUploadResponse.add(filename, size, MessageUtils.message("upload.exceed.maxSize"));
continue;
} catch (FileNameLengthLimitExceededException e) {
ajaxUploadResponse.add(filename, size, MessageUtils.message("upload.filename.exceed.length"));
continue;
}
}
return ajaxUploadResponse;
}