Search in sources :

Example 11 with CommonsMultipartFile

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);
}
Also used : FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) CommonsMultipartFile(org.springframework.web.multipart.commons.CommonsMultipartFile) BaseTest(com.epam.ta.reportportal.BaseTest) Test(org.junit.jupiter.api.Test)

Example 12 with CommonsMultipartFile

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);
}
Also used : CommonsMultipartFile(org.springframework.web.multipart.commons.CommonsMultipartFile) BaseTest(com.epam.ta.reportportal.BaseTest) Test(org.junit.jupiter.api.Test)

Example 13 with CommonsMultipartFile

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))));
}
Also used : Random(java.util.Random) CommonsMultipartFile(org.springframework.web.multipart.commons.CommonsMultipartFile) BaseTest(com.epam.ta.reportportal.BaseTest) Test(org.junit.jupiter.api.Test)

Example 14 with CommonsMultipartFile

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);
}
Also used : ConfigurationLocator(org.mifos.framework.util.ConfigurationLocator) CommonsMultipartFile(org.springframework.web.multipart.commons.CommonsMultipartFile) File(java.io.File) BufferedImage(java.awt.image.BufferedImage) Graphics2D(java.awt.Graphics2D)

Example 15 with CommonsMultipartFile

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());
    }
}
Also used : LinkedMultiValueMap(org.springframework.util.LinkedMultiValueMap) HashMap(java.util.HashMap) UnsupportedEncodingException(java.io.UnsupportedEncodingException) DefaultMultipartHttpServletRequest(org.springframework.web.multipart.support.DefaultMultipartHttpServletRequest) DiskFileItemFactory(org.apache.commons.fileupload.disk.DiskFileItemFactory) CommonsMultipartFile(org.springframework.web.multipart.commons.CommonsMultipartFile) FileItem(org.apache.commons.fileupload.FileItem) CommonsMultipartFile(org.springframework.web.multipart.commons.CommonsMultipartFile) MultipartFile(org.springframework.web.multipart.MultipartFile) ServletFileUpload(org.apache.commons.fileupload.servlet.ServletFileUpload) FileUploadException(org.apache.commons.fileupload.FileUploadException)

Aggregations

CommonsMultipartFile (org.springframework.web.multipart.commons.CommonsMultipartFile)23 InputStream (java.io.InputStream)9 IOException (java.io.IOException)8 File (java.io.File)7 BaseTest (com.epam.ta.reportportal.BaseTest)5 Test (org.junit.jupiter.api.Test)5 MifosRuntimeException (org.mifos.core.MifosRuntimeException)4 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)4 MultipartFile (org.springframework.web.multipart.MultipartFile)4 FileItem (org.apache.commons.fileupload.FileItem)3 BufferedInputStream (java.io.BufferedInputStream)2 FileInputStream (java.io.FileInputStream)2 DiskFileItem (org.apache.commons.fileupload.disk.DiskFileItem)2 Metadata (org.apache.tika.metadata.Metadata)2 MimeTypes (org.apache.tika.mime.MimeTypes)2 LocalDate (org.joda.time.LocalDate)2 CreateAccountFeeDto (org.mifos.dto.domain.CreateAccountFeeDto)2 CreateAccountPenaltyDto (org.mifos.dto.domain.CreateAccountPenaltyDto)2 UploadedFileDto (org.mifos.dto.screen.UploadedFileDto)2 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)2