Examples of CommonsMultipartFile


Examples of org.springframework.web.multipart.commons.CommonsMultipartFile

          sendResponse(response, jsonObject);
          return;
        }

        MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request;
        CommonsMultipartFile file = (CommonsMultipartFile) multipartRequest.getFile("file");

        // the directory to upload to
        String uploadDir = servletContext.getRealPath("/resources") + "/" + request.getRemoteUser() + "/";

        // Create the directory if it doesn't exist
        File dirPath = new File(uploadDir);

        if (!dirPath.exists()) {
            dirPath.mkdirs();
        }

        //retrieve the file data
        InputStream stream = file.getInputStream();

        //write the file to the file specified
        OutputStream bos = new FileOutputStream(uploadDir + file.getOriginalFilename());
        int bytesRead;
        byte[] buffer = new byte[8192];

        while ((bytesRead = stream.read(buffer, 0, 8192)) != -1) {
            bos.write(buffer, 0, bytesRead);
        }

        bos.close();

        //close the stream
        stream.close();
       

        // place the data into the request for retrieval on next page
        jsonObject.put("name", fileUpload.getName());
        jsonObject.put("fileName", file.getOriginalFilename());
        jsonObject.put("contentType", file.getContentType());
        jsonObject.put("size", file.getSize() + " bytes");
        jsonObject.put("location", dirPath.getAbsolutePath() + Constants.FILE_SEP + file.getOriginalFilename());

        String link = request.getContextPath() + "/resources" + "/" + request.getRemoteUser() + "/";
        jsonObject.put("link", link + file.getOriginalFilename());

        sendResponse(response, jsonObject);
    }
View Full Code Here

Examples of org.springframework.web.multipart.commons.CommonsMultipartFile

            return "fileupload";
        }

        MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request;
        CommonsMultipartFile file = (CommonsMultipartFile) multipartRequest.getFile("file");

        // the directory to upload to
        String uploadDir = getServletContext().getRealPath("/resources");

        // The following seems to happen when running jetty:run
        if (uploadDir == null) {
            uploadDir = new File("src/main/webapp/resources").getAbsolutePath();
        }
        uploadDir += "/" + request.getRemoteUser() + "/";

        // Create the directory if it doesn't exist
        File dirPath = new File(uploadDir);

        if (!dirPath.exists()) {
            dirPath.mkdirs();
        }

        //retrieve the file data
        InputStream stream = file.getInputStream();

        //write the file to the file specified
        OutputStream bos = new FileOutputStream(uploadDir + file.getOriginalFilename());
        int bytesRead;
        byte[] buffer = new byte[8192];

        while ((bytesRead = stream.read(buffer, 0, 8192)) != -1) {
            bos.write(buffer, 0, bytesRead);
        }

        bos.close();

        //close the stream
        stream.close();

        // place the data into the request for retrieval on next page
        request.setAttribute("friendlyName", fileUpload.getName());
        request.setAttribute("fileName", file.getOriginalFilename());
        request.setAttribute("contentType", file.getContentType());
        request.setAttribute("size", file.getSize() + " bytes");
        request.setAttribute("location", dirPath.getAbsolutePath() + Constants.FILE_SEP + file.getOriginalFilename());

        String link = request.getContextPath() + "/resources" + "/" + request.getRemoteUser() + "/";
        request.setAttribute("link", link + file.getOriginalFilename());

        return getSuccessView();
    }
View Full Code Here

Examples of org.springframework.web.multipart.commons.CommonsMultipartFile

      // }

      String realPath = request.getSession().getServletContext()
          .getRealPath("");
     
      CommonsMultipartFile file = form.getFile();

      String folder = "upload";
      String originalFilename = file.getOriginalFilename();
      // String actualFilename = "["+originalFilename+"]";

      try {

        // File dest = new File(realPath + "/upload/dest/"
        // + originalFilename);
        //
        // file.transferTo(dest);

        GridFS gridFs = new GridFS(mongoTemplate.getDb(), folder);
        GridFSInputFile gfsFile = gridFs.createFile(file.getFileItem()
            .getInputStream());

        gfsFile.setFilename(originalFilename);
        gfsFile.save();
View Full Code Here

Examples of org.springframework.web.multipart.commons.CommonsMultipartFile

            return new ResponseEntity<>(response, HttpStatus.BAD_REQUEST);
        }

        String format = item.getFormat();
        String searchKeys = item.getSearchkeys();
        CommonsMultipartFile file = item.getFile();

        logger.debug("receiving file: '" +  file.getOriginalFilename() + "'");
        logger.debug("file format: '" +  format + "'");
        logger.debug("search keys: '" + searchKeys + "'");

        DendriteGraph graph = metaGraphService.getDendriteGraph(graphId);
        if (graph == null) {
            response.put("status", "error");
            response.put("msg", "cannot find graph '" + graphId + "'");
            return new ResponseEntity<>(response, HttpStatus.NOT_FOUND);
        }

        try {
            // extract search indices from client JSON
            JSONObject jsonKeys = new JSONObject(searchKeys);
            JSONArray jsonVertices = jsonKeys.getJSONArray("vertices");
            JSONArray jsonEdges = jsonKeys.getJSONArray("edges");

            // build search indices for vertices
            for (int i = 0; i < jsonVertices.length(); ++i){
              JSONObject jsonVertex = jsonVertices.getJSONObject(i);
              String key = jsonVertex.getString("name");
              String type = jsonVertex.getString("type");

              // create the search index (if it doesn't already exist and isn't a reserved key)
              if (graph.getType(key) == null && !RESERVED_KEYS.contains(key)) {
                  Class cls;
                  List<Parameter> parameters = new ArrayList<>();

                  if (type.equals("string")) {
                      cls = String.class;
                      parameters.add(Parameter.of(Mapping.MAPPING_PREFIX, Mapping.STRING));
                  } else if (type.equals("text")) {
                      cls = String.class;
                      parameters.add(Parameter.of(Mapping.MAPPING_PREFIX, Mapping.TEXT));
                  } else if (type.equals("integer")) {
                      cls = Integer.class;
                  } else if (type.equals("float")) {
                      cls = FullFloat.class;
                  } else if (type.equals("double")) {
                      cls = FullDouble.class;
                  } else if (type.equals("geocoordinate")) {
                      cls = Geoshape.class;
                  } else {
                      graph.rollback();
                      response.put("status", "error");
                      response.put("msg", "unknown type '" + type + "'");
                      return new ResponseEntity<>(response, HttpStatus.NOT_FOUND);
                  }

                  graph.makeKey(key)
                          .dataType(cls)
                          .indexed(Vertex.class)
                          .indexed(DendriteGraph.INDEX_NAME, Vertex.class, parameters.toArray(new Parameter[parameters.size()]))
                          .make();
              }
            }

            // build search indices for edges
            for (int i = 0; i < jsonEdges.length(); ++i){
              JSONObject jsonEdge = jsonEdges.getJSONObject(i);
              String key = jsonEdge.getString("name");
              String type = jsonEdge.getString("type");

              // create the search index (if it doesn't already exist and isn't a reserved key)
              if (graph.getType(key) == null && !RESERVED_KEYS.contains(key)) {
                  Class cls;
                  List<Parameter> parameters = new ArrayList<>();

                  if (type.equals("string")) {
                      cls = String.class;
                      parameters.add(Parameter.of(Mapping.MAPPING_PREFIX, Mapping.STRING));
                  } else if (type.equals("text")) {
                      cls = String.class;
                      parameters.add(Parameter.of(Mapping.MAPPING_PREFIX, Mapping.TEXT));
                  } else if (type.equals("integer")) {
                      cls = Integer.class;
                  } else if (type.equals("float")) {
                      cls = FullFloat.class;
                  } else if (type.equals("double")) {
                      cls = FullDouble.class;
                  } else if (type.equals("geocoordinate")) {
                      cls = Geoshape.class;
                  } else {
                      graph.rollback();
                      response.put("status", "error");
                      response.put("msg", "unknown type '" + type + "'");
                      return new ResponseEntity<>(response, HttpStatus.NOT_FOUND);
                  }

                  graph.makeKey(key)
                          .dataType(cls)
                          .indexed(Edge.class)
                          .indexed(DendriteGraph.INDEX_NAME, Edge.class, parameters.toArray(new Parameter[parameters.size()]))
                          .make();
              }
            }

            // commit the indices
            graph.commit();

            InputStream inputStream = file.getInputStream();
            if (format.equalsIgnoreCase("GraphSON")) {
                GraphSONReader.inputGraph(graph, inputStream);
            } else if (format.equalsIgnoreCase("GraphML")) {
                GraphMLReader.inputGraph(graph, inputStream);
            } else if (format.equalsIgnoreCase("GML")) {
View Full Code Here

Examples of org.springframework.web.multipart.commons.CommonsMultipartFile

public class MultipartFileUploadEditor extends PropertyEditorSupport {
 
  @Override
  public String getAsText() {
    if (getValue() != null) {
      CommonsMultipartFile multipart = (CommonsMultipartFile) getValue();
      return multipart.getOriginalFilename();
    }
    return "";
  }
View Full Code Here

Examples of org.springframework.web.multipart.commons.CommonsMultipartFile

            saveMessage(request, getText("objectPhoto.deleted", locale));
        } else {
            MultipartHttpServletRequest multipartRequest =
                    (MultipartHttpServletRequest) request;
            CommonsMultipartFile file =
                    (CommonsMultipartFile) multipartRequest.getFile("file");
            if (file.getSize() > 0) {

                String wayToPhoto = ImageUtil.getUniqueJPEGFile(request);
                OutputStream fl = new FileOutputStream(FileHelper.getCurrentPath(request) + wayToPhoto);
                fl.write(file.getBytes());
                fl.close();
                InputStream inputStream = new FileInputStream(FileHelper.getCurrentPath(request) + wayToPhoto);
                //filling blob field

                objectPhoto.setPhotoBlob(Hibernate.createBlob(ImageUtil.scaleImage(inputStream, 400, 400)));
View Full Code Here

Examples of org.springframework.web.multipart.commons.CommonsMultipartFile


        Expert expert = (Expert) command;

        MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request;
        CommonsMultipartFile frontFile = (CommonsMultipartFile) multipartRequest.getFile("frontFile");
        CommonsMultipartFile backFile = (CommonsMultipartFile) multipartRequest.getFile("backFile");


        if (expert.getExpertId() != null) {
            String dateNew;
            Date d;


            d = expert.getDataComplite();
//            d.setMonth(d.getMonth()); ?? for what this code
            expert.setDataComplite(d);
            dateNew = StringUtil.formatDate(d);
            expert.setDateForLook(dateNew);
            d = expert.getDataStart();
//            d.setMonth(d.getMonth());
            expert.setDataStart(d);
            dateNew = StringUtil.formatDate(d);
            expert.setStartDateForLook(dateNew);

            if (frontFile.getSize() > 0) {

                Date date = new Date();
                String wayToPhoto = String.valueOf(date.getTime()) + ".jpg";
                OutputStream fl = null;
                fl = new FileOutputStream(FileHelper.getCurrentPath(request) + wayToPhoto);
                fl.write(frontFile.getBytes());
                fl.close();
                InputStream inputStream = new FileInputStream(FileHelper.getCurrentPath(request) + wayToPhoto);
                expert.setFrontExpertBlob(Hibernate.createBlob(ImageUtil.scaleImage(inputStream)));
                expert.setFrontWayToPhoto(wayToPhoto);

            } else {
                Expert ex = expertManager.getExpertById(expert.getExpertId());
                expert.setFrontExpertBlob(ex.getFrontExpertBlob());
                expert.setFrontWayToPhoto(ex.getFrontWayToPhoto());
            }


            if (backFile.getSize() > 0) {

                           Date date = new Date();
                           String wayToPhoto = String.valueOf(date.getTime()) + ".jpg";
                           OutputStream fl = null;
                           fl = new FileOutputStream(FileHelper.getCurrentPath(request) + wayToPhoto);
                           fl.write(backFile.getBytes());
                           fl.close();
                           InputStream inputStream = new FileInputStream(FileHelper.getCurrentPath(request) + wayToPhoto);
                           expert.setBackExpertBlob(Hibernate.createBlob(ImageUtil.scaleImage(inputStream)));
                           expert.setBackWayToPhoto(wayToPhoto);

                       } else {
                           Expert ex = expertManager.getExpertById(expert.getExpertId());
                           if (ex.getBackExpertBlob()!=null && ex.getBackWayToPhoto()!=null){
                               expert.setBackExpertBlob(ex.getBackExpertBlob());
                               expert.setBackWayToPhoto(ex.getBackWayToPhoto());
                           else{
                               expert.setBackWayToPhoto("no photo");
                           }

                       }




            expertManager.updateExpert(expert);

            if (expert.isEdited()) {
                return new ModelAndView("redirect:updating.html?id=" + expert.getExpertId() + "&fieldId=" + request.getParameter("fieldId"));
            }

        } else {

            Date d = expert.getDataComplite();
//            d.setMonth(d.getMonth());
            expert.setDataComplite(d);
            String dateNew = StringUtil.formatDate(d);
            expert.setDateForLook(dateNew);
            d = expert.getDataStart();
//            d.setMonth(d.getMonth());
            expert.setDataComplite(d);
            dateNew = StringUtil.formatDate(d);
            expert.setStartDateForLook(dateNew);

            if (frontFile.getSize() > 0) {
                Date date = new Date();
                String wayToPhoto = String.valueOf(date.getTime()) + ".jpg";
                OutputStream fl = new FileOutputStream(FileHelper.getCurrentPath(request) + wayToPhoto);
                fl.write(frontFile.getBytes());
                fl.close();
                InputStream inputStream = new FileInputStream(FileHelper.getCurrentPath(request) + wayToPhoto);
                expert.setFrontExpertBlob(Hibernate.createBlob(ImageUtil.scaleImage(inputStream)));
                expert.setFrontWayToPhoto(wayToPhoto);

            }

             if (backFile.getSize() > 0) {
                Date date = new Date();
                String wayToPhoto = String.valueOf(date.getTime()) + ".jpg";
                OutputStream fl = new FileOutputStream(FileHelper.getCurrentPath(request) + wayToPhoto);
                fl.write(backFile.getBytes());
                fl.close();
                InputStream inputStream = new FileInputStream(FileHelper.getCurrentPath(request) + wayToPhoto);
                expert.setBackExpertBlob(Hibernate.createBlob(ImageUtil.scaleImage(inputStream)));
                expert.setBackWayToPhoto(wayToPhoto);
View Full Code Here

Examples of org.springframework.web.multipart.commons.CommonsMultipartFile

        }
        String buildingObjectId = request.getParameter("buildingObjectId");
        //  Loader loader = (Loader) command;
        MultipartHttpServletRequest multipartRequest =
                (MultipartHttpServletRequest) request;
        CommonsMultipartFile file =
                (CommonsMultipartFile) multipartRequest.getFile("file");

        if (file.getSize() > 0) {
            InputStream inputStream = file.getInputStream();
            String filename = FileHelper.getUniqueFileName(request);

            OutputStream outputStream = new FileOutputStream(FileHelper.getCurrentPath(request) + filename);

            int c;
View Full Code Here

Examples of org.springframework.web.multipart.commons.CommonsMultipartFile

       
      }
      constructionDefect.setDefectParameters(parameters);

      MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request;
      CommonsMultipartFile file = (CommonsMultipartFile) multipartRequest
          .getFile("file");
      if (file.getSize() > 0) {
        String fileName = ImageUtil.getUniqueJPEGFile(request);
        FileOutputStream fileOutputStream = new FileOutputStream(
            FileHelper.getCurrentPath(request) + fileName);
        fileOutputStream.write(file.getBytes());
        fileOutputStream.close();
        InputStream imageStream = ImageUtil.scaleImage(
            new FileInputStream(FileHelper.getCurrentPath(request)
                + fileName), 400, 400);
View Full Code Here

Examples of org.springframework.web.multipart.commons.CommonsMultipartFile

        Date d = objectInspection.getContractDate();
        objectInspection.setDateForLook(StringUtil.formatDate(d));

        MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request;

        CommonsMultipartFile fileCertificate = (CommonsMultipartFile) multipartRequest.getFile("certificate.file");
        CommonsMultipartFile fileDemand = (CommonsMultipartFile) multipartRequest.getFile("demand.file");

        if (objectInspection.getObjectId() != null) {
            objectInspection = objectInspectionManager.getObjectInspectionBy(objectInspection.getObjectId());

            Photo photo = photoManager.update(photoManager.getByIdPhoto(objectInspection.getCertificate().getPhotoId()), fileCertificate, FileHelper.getCurrentPath(request));
            //objectInspection.setCertificate(photo);

            photo = photoManager.update(photoManager.getByIdPhoto(objectInspection.getDemand().getPhotoId()), fileDemand, FileHelper.getCurrentPath(request));
            //objectInspection.setDemand(photo);
            objectInspectionManager.updateObjectInspection(objectInspection);
            return new ModelAndView("redirect:/lookObjectInspection.html");

        } else {
            if (fileCertificate.getSize() > 0) {
                Photo photo = photoManager.insertPhoto(fileCertificate, FileHelper.getCurrentPath(request));
                objectInspection.setCertificate(photo);
            }
            if (fileDemand.getSize() > 0) {
                Photo photo = photoManager.insertPhoto(fileDemand, FileHelper.getCurrentPath(request));
                objectInspection.setDemand(photo);
            }

View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.