use of org.springframework.web.multipart.commons.CommonsMultipartFile in project commons-dao by reportportal.
the class CommonDataStoreServiceTest method saveAndLoadTest.
@Test
void saveAndLoadTest() throws IOException {
CommonsMultipartFile multipartFile = getMultipartFile("meh.jpg");
String fileId = dataStoreService.saveThumbnail(multipartFile.getOriginalFilename(), multipartFile.getInputStream());
Optional<InputStream> content = dataStoreService.load(fileId);
assertTrue(content.isPresent());
dataStoreService.delete(fileId);
}
use of org.springframework.web.multipart.commons.CommonsMultipartFile in project commons-dao by reportportal.
the class CommonDataStoreServiceTest method saveTest.
@Test
void saveTest() throws IOException {
CommonsMultipartFile multipartFile = getMultipartFile("meh.jpg");
String fileId = dataStoreService.save(multipartFile.getOriginalFilename(), multipartFile.getInputStream());
assertNotNull(fileId);
assertTrue(Files.exists(Paths.get(storageRootPath, dataEncoder.decode(fileId))));
dataStoreService.delete(fileId);
}
use of org.springframework.web.multipart.commons.CommonsMultipartFile in project commons-dao by reportportal.
the class CommonDataStoreServiceTest method saveAndDeleteTest.
@Test
void saveAndDeleteTest() throws IOException {
CommonsMultipartFile multipartFile = getMultipartFile("meh.jpg");
Random random = new Random();
String fileId = dataStoreService.save(random.nextLong() + "/" + multipartFile.getOriginalFilename(), multipartFile.getInputStream());
dataStoreService.delete(fileId);
assertFalse(Files.exists(Paths.get(dataEncoder.decode(fileId))));
}
use of org.springframework.web.multipart.commons.CommonsMultipartFile in project head by mifos.
the class LogoServiceFacadeWebTier method uploadNewLogo.
public void uploadNewLogo(CommonsMultipartFile logo) throws IOException {
BufferedImage bufferedImage = ImageIO.read(logo.getInputStream());
BufferedImage finalImage = null;
if (bufferedImage.getWidth() > MAX_WIDTH || bufferedImage.getHeight() > MAX_HEIGHT) {
float wRatio, hRatio;
if (bufferedImage.getWidth() >= bufferedImage.getHeight()) {
wRatio = MAX_WIDTH / bufferedImage.getWidth();
hRatio = MAX_HEIGHT / bufferedImage.getHeight();
} else {
wRatio = MAX_HEIGHT / bufferedImage.getWidth();
hRatio = MAX_WIDTH / bufferedImage.getHeight();
}
float resizeRatio = Math.min(wRatio, hRatio);
float newHeight = bufferedImage.getHeight() * resizeRatio;
float newWidth = bufferedImage.getWidth() * resizeRatio;
finalImage = new BufferedImage((int) newWidth, (int) newHeight, bufferedImage.getType());
Graphics2D g = finalImage.createGraphics();
g.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR);
g.drawImage(bufferedImage, 0, 0, (int) newWidth, (int) newHeight, 0, 0, bufferedImage.getWidth(), bufferedImage.getHeight(), null);
g.dispose();
} else {
finalImage = bufferedImage;
}
ConfigurationLocator configurationLocator = new ConfigurationLocator();
File dir = new File(configurationLocator.getConfigurationDirectory() + File.separator + configurationLocator.getLogoDirectory() + File.separator);
dir.mkdirs();
File file = new File(dir, configurationLocator.getLogoName());
ImageIO.write(finalImage, "png", file);
}
use of org.springframework.web.multipart.commons.CommonsMultipartFile in project Gemma by PavlidisLab.
the class CommonsMultipartMonitoredResolver method resolveMultipart.
@Override
public MultipartHttpServletRequest resolveMultipart(HttpServletRequest request) throws MultipartException {
String enc = determineEncoding(request);
ServletFileUpload fileUpload = this.newFileUpload(request);
DiskFileItemFactory newFactory = (DiskFileItemFactory) fileUpload.getFileItemFactory();
fileUpload.setSizeMax(sizeMax);
newFactory.setRepository(this.uploadTempDir);
fileUpload.setHeaderEncoding(enc);
try {
MultiValueMap<String, MultipartFile> multipartFiles = new LinkedMultiValueMap<>();
Map<String, String[]> multipartParams = new HashMap<>();
// Extract multipart files and multipart parameters.
List<?> fileItems = fileUpload.parseRequest(request);
for (Object fileItem1 : fileItems) {
FileItem fileItem = (FileItem) fileItem1;
if (fileItem.isFormField()) {
String value;
String fieldName = fileItem.getFieldName();
try {
value = fileItem.getString(enc);
} catch (UnsupportedEncodingException ex) {
logger.warn("Could not decode multipart item '" + fieldName + "' with encoding '" + enc + "': using platform default");
value = fileItem.getString();
}
String[] curParam = multipartParams.get(fieldName);
if (curParam == null) {
// simple form field
multipartParams.put(fieldName, new String[] { value });
} else {
// array of simple form fields
String[] newParam = StringUtils.addStringToArray(curParam, value);
multipartParams.put(fieldName, newParam);
}
} else {
// multipart file field
MultipartFile file = new CommonsMultipartFile(fileItem);
multipartFiles.set(file.getName(), file);
if (logger.isDebugEnabled()) {
logger.debug("Found multipart file [" + file.getName() + "] of size " + file.getSize() + " bytes with original filename [" + file.getOriginalFilename() + "]");
}
}
}
return new DefaultMultipartHttpServletRequest(request, multipartFiles, multipartParams, null);
} catch (FileUploadException ex) {
return new FailedMultipartHttpServletRequest(request, ex.getMessage());
}
}
Aggregations