Package org.springframework.web.multipart

Examples of org.springframework.web.multipart.MultipartFile


      String currentFolderStr, Boolean mark) throws Exception {
    ResourceType type = ResourceType.getDefaultResourceType(typeStr);
    try {
      MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request;
      // We upload just one file at the same time
      MultipartFile uplFile = multipartRequest.getFileMap().entrySet()
          .iterator().next().getValue();
      // Some browsers transfer the entire source path not just the
      // filename
      String filename = FilenameUtils.getName(uplFile
          .getOriginalFilename());
      log.debug("Parameter NewFile: {}", filename);
      String ext = FilenameUtils.getExtension(filename);
      if (type.isDeniedExtension(ext)) {
        return UploadResponse.getInvalidFileTypeError(request);
      }
      if (type.equals(ResourceType.IMAGE)
          && !ImageUtils.isImage(uplFile.getInputStream())) {
        return UploadResponse.getInvalidFileTypeError(request);
      }
      String fileUrl;
      CmsSite site = CmsUtils.getSite(request);
      MarkConfig conf = site.getConfig().getMarkConfig();
      if (mark == null) {
        mark = conf.getOn();
      }
      boolean isImg = type.equals(ResourceType.IMAGE);
      if (site.getConfig().getUploadToDb()) {
        if (mark && isImg) {
          File tempFile = mark(uplFile, conf);
          fileUrl = dbFileMng.storeByExt(site.getUploadPath(), ext,
              new FileInputStream(tempFile));
          tempFile.delete();
        } else {
          fileUrl = dbFileMng.storeByExt(site.getUploadPath(), ext,
              uplFile.getInputStream());
        }
        // 加上访问地址
        String dbFilePath = site.getConfig().getDbFileUri();
        fileUrl = request.getContextPath() + dbFilePath + fileUrl;
      } else if (site.getUploadFtp() != null) {
        Ftp ftp = site.getUploadFtp();
        if (mark && isImg) {
          File tempFile = mark(uplFile, conf);
          fileUrl = ftp.storeByExt(site.getUploadPath(), ext,
              new FileInputStream(tempFile));
          tempFile.delete();
        } else {
          fileUrl = ftp.storeByExt(site.getUploadPath(), ext, uplFile
              .getInputStream());
        }
        // 加上url前缀
        fileUrl = ftp.getUrl() + fileUrl;
      } else {
View Full Code Here


  @RequestMapping(value="/FileUploaded")

    public synchronized ModelAndView IndividualFileUploaded(@ModelAttribute("fileUploadForm") FileUpload fileUploaded) {
   
    MultipartFile multipartFile = fileUploaded.getFile();
   
       ModelAndView modelAndView  = null;
      
    String fileName="";

    if(multipartFile!=null){
      fileName = multipartFile.getOriginalFilename();
     
      // Extract File Name
      // fileName = Certificate_2941130.cert
          
         fileName= fileName.substring(12,19);
        
     
      //Query the Database and get the blob
        
          Pki publicKey =  pkiBO.findPKI(fileName);
     
         
      //Verifying THe certificate using public key
        CertificateFactory cf = null;
        try {
          cf = CertificateFactory.getInstance("X.509");
        } catch (CertificateException e2) {
          // TODO Auto-generated catch block
          e2.printStackTrace();
        }
            X509Certificate cert = null;
        try {
          cert = (X509Certificate)cf.generateCertificate(multipartFile.getInputStream());
        } catch (CertificateException | IOException e1) {
          // TODO Auto-generated catch block
          e1.printStackTrace();
        }
           
View Full Code Here

  
    @RequestMapping(value="/FileUploaded")

         public synchronized ModelAndView MerchantFileUploaded(@ModelAttribute("fileUploadForm") FileUpload fileUploaded) {
     
      MultipartFile multipartFile = fileUploaded.getFile();
     
         ModelAndView modelAndView  = null;
        
      String fileName="";
  
      if(multipartFile!=null){
        fileName = multipartFile.getOriginalFilename();
       
        // Extract File Name
        // fileName = Certificate_2941130.cert
            
           fileName= fileName.substring(12,19);
          
       
        //Query the Database and get the blob
          
            Pki publicKey =  pkiBO.findPKI(fileName);
       
           
        //Verifying THe certificate using public key
          CertificateFactory cf = null;
          try {
            cf = CertificateFactory.getInstance("X.509");
          } catch (CertificateException e2) {
            // TODO Auto-generated catch block
            e2.printStackTrace();
          }
              X509Certificate cert = null;
          try {
            cert = (X509Certificate)cf.generateCertificate(multipartFile.getInputStream());
          } catch (CertificateException | IOException e1) {
            // TODO Auto-generated catch block
            e1.printStackTrace();
          }
             
View Full Code Here

    }

    @Test
    public void uploadLogoForOperaAndIEShouldReturnPreviewInResponce()
            throws IOException, ImageProcessException {
        MultipartFile file = new MockMultipartFile("qqfile", validImage);

        ResponseEntity<String> actualResponseEntity = administrationController.uploadLogo(file);

        verify(logoControllerUtils).prepareResponse(eq(file), any(HttpHeaders.class), any(HashMap.class));
    }
View Full Code Here

    }

    @Test
    public void uploadIconForOperaAndIEShouldReturnPreviewInResponce()
            throws IOException, ImageProcessException {
        MultipartFile file = new MockMultipartFile("qqfile", validImage);

        administrationController.uploadFavIcon(file);

        verify(favIconPngControllerUtils).prepareResponse(eq(file), any(HttpHeaders.class), any(HashMap.class));
    }
View Full Code Here

    @Test
    @SuppressWarnings("unchecked")
    public void uploadAvatarForOperaAndIEShouldReturnPreviewInResponce()
            throws IOException, ImageProcessException {
        MultipartFile file = new MockMultipartFile("qqfile", validAvatar);

        ResponseEntity<String> actualResponseEntity = avatarController.uploadAvatar(file);

        verify(imageControllerUtils).prepareResponse(eq(file), any(HttpHeaders.class), any(HashMap.class));
    }
View Full Code Here

        return result;
    }

    @Test(expectedExceptions = {IllegalArgumentException.class})
    public void validateImageFormatInFileShouldNotWorkWithPassedNull() throws ImageFormatException {
        MultipartFile nullMultipartFile = null;
        imageService.validateImageFormat(nullMultipartFile);
    }
View Full Code Here

    @Test
    @SuppressWarnings("unchecked")
    public void uploadAvatarForOperaAndIEShouldReturnPreviewInResponce()
            throws IOException, ImageProcessException {
        MultipartFile file = new MockMultipartFile("qqfile", validAvatar);
        String expectedBody = "{\"srcPrefix\":\"data:image/jpeg;base64,\",\"srcImage\":\"srcImage\",\"success\":\"true\"}";
        when(imageService.preProcessAndEncodeInString64(validAvatar)).thenReturn(IMAGE_BYTE_ARRAY_IN_BASE_64_STRING);
        when(imageControllerUtils.getResponceJSONString(Matchers.anyMap())).thenReturn(expectedBody);
        Map<String, String> responseContent = new HashMap<String, String>();
        HttpHeaders responseHeaders = new HttpHeaders();
        responseHeaders.setContentType(MediaType.TEXT_HTML);

        ResponseEntity<String> actualResponseEntity = imageControllerUtils.prepareResponse(file, responseHeaders, responseContent);

        verify(imageService).validateImageFormat(file);
        verify(imageService).validateImageSize(file.getBytes());
        assertEquals(actualResponseEntity.getStatusCode(), HttpStatus.OK);
        assertEquals(actualResponseEntity.getBody(), expectedBody);
        HttpHeaders headers = actualResponseEntity.getHeaders();
        assertEquals(headers.getContentType(), MediaType.TEXT_HTML);
    }
View Full Code Here

    InputStream in = null;
    OutputStream out = null;
    File file = null;
    try {
      MultipartFile mpfile = mpr.getFile("Filedata");
      in = mpfile.getInputStream();
      file = driver.getFile(dir, fileName);
      out = new FileOutputStream(file);
      IOUtils.copy(in, out);
    } catch (IOException e) {
      throw new AjxpDriverException("Cannot upload file.", e);
View Full Code Here

        StringBuilder csvBuilder = new StringBuilder();
        csvBuilder.append("Name,Given Name,Additional Name,Family Name,Yomi Name,Given Name Yomi,Additional Name Yomi,Family Name Yomi,Name Prefix,Name Suffix,Initials,Nickname,Short Name,Maiden Name,Birthday,Gender,Location,Billing Information,Directory Server,Mileage,Occupation,Hobby,Sensitivity,Priority,Subject,Notes,Group Membership,E-mail 1 - Type,E-mail 1 - Value,Phone 1 - Type,Phone 1 - Value\n");
        csvBuilder.append("John Doe,John,,Doe,,,,,,,,,,,,,,,,,,,,,,,,* Other,john.doe@sparcedge.com,Work,843-555-5555");
        InputStream is = new ByteArrayInputStream(csvBuilder.toString().getBytes());

        MultipartFile mockFile = new MockMultipartFile("googleContacts", "googleContacts.csv", "plain/text", is);
        List<Contact> contacts = invitationService.parseContactsGoogle(mockFile);
        assertTrue(contacts.size() == 1);
        assertTrue(contacts.get(0).getEmail().equals("john.doe@sparcedge.com"));
    }
View Full Code Here

TOP

Related Classes of org.springframework.web.multipart.MultipartFile

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.