Package org.apache.commons.fileupload.disk

Examples of org.apache.commons.fileupload.disk.DiskFileItem


                throw new RuntimeException(e);
            }

            for (FileItem item : items) {
                if ("backgroundImage".equals(item.getFieldName())) {
                    final DiskFileItem diskItem = (DiskFileItem) item;

                    // Create the path to the upload directory.
                    File dir = GraphicalViewsCommon.getUploadDir();

                    // Create the image file name.
                    String filename = GraphicalViewsCommon.getNextImageFilename(dir, diskItem.getName());

                    // Save the file.
                    FileOutputStream fos = new FileOutputStream(new File(dir, filename));
                    StreamUtils.transfer(diskItem.getInputStream(), fos);
                    fos.close();

                    view.setBackgroundFilename(ImageUploadServletDefinition.IMAGE_DIR + "/" + filename);
                }
            }
View Full Code Here


      return null;
  }

  List<File> fileList = new ArrayList<File>(items.size());
  for (int i = 0; i < items.size(); i++) {
      DiskFileItem fileItem = (DiskFileItem) items.get(i);
      fileList.add(fileItem.getStoreLocation());
  }

  return (File[]) fileList.toArray(new File[fileList.size()]);
    }
View Full Code Here

      return null;
  }

  List<String> fileNames = new ArrayList<String>(items.size());
  for (int i = 0; i < items.size(); i++) {
      DiskFileItem fileItem = (DiskFileItem) items.get(i);
      fileNames.add(getCanonicalName(fileItem.getName()));
  }

  return (String[]) fileNames.toArray(new String[fileNames.size()]);
    }
View Full Code Here

      return null;
  }

  List<String> fileNames = new ArrayList<String>(items.size());
  for (int i = 0; i < items.size(); i++) {
      DiskFileItem fileItem = (DiskFileItem) items.get(i);
      fileNames.add(fileItem.getStoreLocation().getName());
  }

  return (String[]) fileNames.toArray(new String[fileNames.size()]);
    }
View Full Code Here

        logger.debug("Started");
        long timer = System.currentTimeMillis();

        FileUpload fileUpload = ((ParamBean) jParams).getFileUpload();
        if (fileUpload != null) {
            DiskFileItem fileItem = fileUpload.getFileItems().get("csvFile");
            if (fileItem == null) {
                logger.error("Couldn't find CSV file in form parameter name 'csvFile' aborting batch creation !");
                displayUsers( request, response, session);
                return;
            }
            String csvSeparator = jParams.getParameter("csvSeparator");
            CSVReader csvReader = new CSVReader(new InputStreamReader(fileItem.getInputStream()), csvSeparator.charAt(0));
            // the first line contains the column names;
            String[] headerElements = csvReader.readNext();
            List<String> headerElementList = Arrays.asList(headerElements);
            int userNamePos = headerElementList.indexOf("j:nodename");
            int passwordPos = headerElementList.indexOf("j:password");
View Full Code Here

            response.sendError(HttpServletResponse.SC_BAD_REQUEST, "No file was submitted");
            return null;
        }

        // take the first one
        DiskFileItem inputFile = fu.getFileItems().values().iterator().next();
        InputStream stream = null;
        String returnedMimeType = fu.getParameterValues("mimeType") != null ? fu.getParameterValues("mimeType")[0]
                : null;
        if (returnedMimeType == null) {
            response.sendError(HttpServletResponse.SC_BAD_REQUEST, "Missing required parameter mimeType");
            return null;
        }

        try {
            ServletOutputStream outputStream = response.getOutputStream();

            stream = inputFile.getInputStream();
            // return a file
            response.setContentType(returnedMimeType);
            response.setHeader("Content-Disposition", "attachment; filename=\""
                    + FilenameUtils.getBaseName(inputFile.getName()) + "."
                    + converterService.getExtension(returnedMimeType) + "\"");

            converterService.convert(stream, inputFile.getContentType(), outputStream, returnedMimeType);

            try {
                outputStream.flush();
            } finally {
                outputStream.close();
            }
        } catch (Exception e) {
            logger
                    .error("Error converting uploaded file " + inputFile.getFieldName() + ". Cause: " + e.getMessage(),
                            e);
            response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, "Exception occurred: " + e.getMessage());
        } finally {
            IOUtils.closeQuietly(stream);
            for (DiskFileItem file : fu.getFileItems().values()) {
View Full Code Here

        if (upload.getFileItems().size() == 0) {
            response.sendError(HttpServletResponse.SC_BAD_REQUEST, "No file was submitted");
            return null;
        }

        DiskFileItem inputFile = upload.getFileItems().values().iterator().next();
        InputStream stream = null;
        try {
            stream = inputFile.getInputStream();
            Metadata metadata = new Metadata();
            metadata.set(Metadata.CONTENT_TYPE, inputFile.getContentType());
            metadata.set(Metadata.RESOURCE_NAME_KEY, inputFile.getFieldName());

            long startTime = System.currentTimeMillis();
           
            String content = textExtractionService.parse(stream, metadata);

            Map<String, Object> model = new HashMap<String, Object>();
           
            Map<String, Object> properties = new HashMap<String, Object>();
            for (String name : metadata.names()) {
                properties.put(name, metadata.isMultiValued(name) ? metadata.getValues(name) : metadata.get(name));
            }
            model.put("metadata", properties);
            model.put("content", content);
            model.put("file", inputFile);
            model.put("extracted", Boolean.TRUE);
            model.put("extractionTime", Long.valueOf(System.currentTimeMillis() - startTime));

            return new ModelAndView(view, model);

        } catch (Exception e) {
            logger.error("Error extracting text for uploaded file " + inputFile.getFieldName() + ". Cause: "
                    + e.getMessage(), e);
            response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, "Exception occurred: " + e.getMessage());
        } finally {
            IOUtils.closeQuietly(stream);
            for (DiskFileItem file : upload.getFileItems().values()) {
View Full Code Here

                final List<?> items = upload.parseRequest(req);

                final Iterator<?> iter = items.iterator();
                while (iter.hasNext()) {
                    final DiskFileItem item = (DiskFileItem) iter.next();

                    if (item.isFormField()) {
                        final String name = item.getFieldName();
                        final List<String> v ;
                        if (params.containsKey(name)) {
                            v = params.get(name);
                        } else {
                            v = new ArrayList<String>();
                            params.put(name,v);
                        }
                        v.add(item.getString(encoding));
                    } else {
                        if (item.getSize() > 0) {
                            files.put(item.getStoreLocation().getName(), item);
                            filesByFieldName.put(item.getFieldName(), item);
                        }
                    }

                }
            } catch (FileUploadException ioe) {
View Full Code Here

            if (ServletFileUpload.isMultipartContent(request)) {
                List items = parseRequest(new ServletRequestContext(request));
                byte[] content = null;
                String fileName = null;
                for (Object item : items) {
                    DiskFileItem diskFileItem = (DiskFileItem) item;
                    String name = diskFileItem.getFieldName();
                    if (name.equals("policyFromFileSystem")) {
                        content = diskFileItem.get();
                        fileName = diskFileItem.getName();
                        int index = fileName.lastIndexOf("\\");
                        fileName = fileName.substring(index + 1);
                    }
                }
                dto = new PolicyDTO();
View Full Code Here

            return null;
        }

        List<File> fileList = new ArrayList<File>(items.size());
        for (int i = 0; i < items.size(); i++) {
            DiskFileItem fileItem = (DiskFileItem) items.get(i);
            fileList.add(fileItem.getStoreLocation());
        }

        return (File[]) fileList.toArray(new File[fileList.size()]);
    }
View Full Code Here

TOP

Related Classes of org.apache.commons.fileupload.disk.DiskFileItem

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.