use of org.springframework.web.multipart.commons.CommonsMultipartFile in project Gemma by PavlidisLab.
the class CommonsMultipartMonitoredResolver method cleanupMultipart.
@Override
public void cleanupMultipart(MultipartHttpServletRequest request) {
if (request instanceof FailedMultipartHttpServletRequest)
return;
Map<String, MultipartFile> multipartFiles = request.getFileMap();
for (MultipartFile multipartFile : multipartFiles.values()) {
CommonsMultipartFile file = (CommonsMultipartFile) multipartFile;
if (logger.isDebugEnabled()) {
logger.debug("Cleaning up multipart file [" + file.getName() + "] with original filename [" + file.getOriginalFilename() + "], stored " + file.getStorageDescription());
}
file.getFileItem().delete();
}
}
use of org.springframework.web.multipart.commons.CommonsMultipartFile in project DCGyunpan by JKchenmin.
the class FileUtil method fileUpLoad.
public List<Map<String, Object>> fileUpLoad(CommonsMultipartFile[] file) {
PropertiesUtil pUtil = new PropertiesUtil();
List<Map<String, Object>> fList = new ArrayList<>();
try {
// 获取系统时间作为文件上传的时间
Date day = new Date();
SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
System.out.println(df.format(day));
String fileTime = df.format(day).toString();
Properties properties = pUtil.readProperties("jdbc.properties");
String filePath = properties.getProperty("filepath");
for (int i = 0; i < file.length; i++) {
String fileName = file[i].getOriginalFilename();
String newFileName = getNewName(fileName);
File dir = new File(filePath, newFileName);
if (!dir.exists()) {
System.out.println("文件不存在,准备创建!");
dir.mkdir();
}
try {
file[i].transferTo(dir);
Map<String, Object> map = new HashMap<>();
// 文件的原来名称
map.put("fileOriginalName", fileName);
// 文件上传到服务器新的名字
map.put("fileNewName", newFileName);
// 文件上传的时间
map.put("fileTime", fileTime);
// 文件上传到服务器的地址
map.put("fileUrl", filePath);
fList.add(map);
} catch (IllegalStateException | IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
Map<String, Object> upFileMap = new HashMap();
upFileMap.put("upFileFlag", true);
fList.add(upFileMap);
} catch (Exception e) {
e.printStackTrace();
Map<String, Object> upFileMap = new HashMap();
upFileMap.put("upFileFlag", false);
fList.add(upFileMap);
}
return fList;
}
use of org.springframework.web.multipart.commons.CommonsMultipartFile in project collect by openforis.
the class FileUploadController method uploadFile.
@RequestMapping(value = "/uploadFile.htm", method = RequestMethod.POST)
@ResponseBody
public String uploadFile(UploadItem uploadItem) throws IOException, SurveyImportException {
CommonsMultipartFile fileData = uploadItem.getFileData();
File file = File.createTempFile("collect_", fileData.getOriginalFilename());
InputStream is = fileData.getInputStream();
FileUtils.copyInputStreamToFile(is, file);
return file.getAbsolutePath();
}
use of org.springframework.web.multipart.commons.CommonsMultipartFile in project collect by openforis.
the class LogoController method uploadLogo.
@RequestMapping(value = "/uploadLogo.htm", method = RequestMethod.POST)
@ResponseBody
public String uploadLogo(UploadItem uploadItem, BindingResult result, @RequestParam String position) throws IOException, SurveyImportException, IdmlParseException {
CommonsMultipartFile fileData = uploadItem.getFileData();
InputStream is = fileData.getInputStream();
ByteArrayOutputStream output = new ByteArrayOutputStream();
IOUtils.copy(is, output);
byte[] byteArray = output.toByteArray();
String contentType = fileData.getContentType();
LogoPosition p = LogoPosition.valueOf(position.toUpperCase());
Logo logo = new Logo(p, byteArray, contentType);
logoManager.save(logo);
return "ok";
}
use of org.springframework.web.multipart.commons.CommonsMultipartFile in project Asqatasun by Asqatasun.
the class AddScenarioFormValidator method checkScenarioFileTypeAndSize.
/**
* @param addScenarioCommand
* @param errors
* @return whether the scenario handled by the current AddScenarioCommand
* has a correct type and size
*/
public boolean checkScenarioFileTypeAndSize(AddScenarioCommand addScenarioCommand, Errors errors) {
if (addScenarioCommand.getScenarioFile() == null) {
// if no file uploaded
LOGGER.debug("empty Scenario File");
errors.rejectValue(GENERAL_ERROR_MSG_KEY, MANDATORY_FIELD_MSG_BUNDLE_KEY);
errors.rejectValue(SCENARIO_FILE_KEY, NO_SCENARIO_UPLOADED_MSG_BUNDLE_KEY);
return false;
}
Metadata metadata = new Metadata();
MimeTypes mimeTypes = TikaConfig.getDefaultConfig().getMimeRepository();
String mime;
try {
CommonsMultipartFile cmf = addScenarioCommand.getScenarioFile();
if (cmf.getSize() > maxFileSize) {
Long maxFileSizeInMega = maxFileSize / 1000000;
String[] arg = { maxFileSizeInMega.toString() };
errors.rejectValue(GENERAL_ERROR_MSG_KEY, MANDATORY_FIELD_MSG_BUNDLE_KEY);
errors.rejectValue(SCENARIO_FILE_KEY, FILE_SIZE_EXCEEDED_MSG_BUNDLE_KEY, arg, "{0}");
return false;
} else if (cmf.getSize() > 0) {
mime = mimeTypes.detect(new BufferedInputStream(cmf.getInputStream()), metadata).toString();
LOGGER.debug("mime " + mime + " " + cmf.getOriginalFilename());
if (!authorizedMimeType.contains(mime)) {
errors.rejectValue(GENERAL_ERROR_MSG_KEY, MANDATORY_FIELD_MSG_BUNDLE_KEY);
errors.rejectValue(SCENARIO_FILE_KEY, NOT_SCENARIO_MSG_BUNDLE_KEY);
return false;
}
} else {
LOGGER.debug("File with size null");
errors.rejectValue(GENERAL_ERROR_MSG_KEY, MANDATORY_FIELD_MSG_BUNDLE_KEY);
errors.rejectValue(SCENARIO_FILE_KEY, NO_SCENARIO_UPLOADED_MSG_BUNDLE_KEY);
return false;
}
} catch (IOException ex) {
LOGGER.warn(ex.getMessage());
errors.rejectValue(SCENARIO_FILE_KEY, NOT_SCENARIO_MSG_BUNDLE_KEY);
errors.rejectValue(GENERAL_ERROR_MSG_KEY, MANDATORY_FIELD_MSG_BUNDLE_KEY);
return false;
}
return true;
}
Aggregations