Package org.apache.commons.fileupload

Examples of org.apache.commons.fileupload.FileItem


      servletRequest.getSession().setAttribute(ProgressMonitor.SESSION_PROGRESS_MONITOR, monitor);

      List items = upload.parseRequest(createRequestContext(servletRequest));

      for (Object item1 : items) {
    FileItem item = (FileItem) item1;
    if (log.isDebugEnabled())
        log.debug("Found item " + item.getFieldName());
    if (item.isFormField()) {
        log.debug("Item is a normal form field");
        List<String> values;
        if (params.get(item.getFieldName()) != null) {
      values = params.get(item.getFieldName());
        } else {
      values = new ArrayList<String>();
        }

        // note: see http://jira.opensymphony.com/browse/WW-633
        // basically, in some cases the charset may be null, so
        // we're just going to try to "other" method (no idea if this
        // will work)
        String charset = servletRequest.getCharacterEncoding();
        if (charset != null) {
      values.add(item.getString(charset));
        } else {
      values.add(item.getString());
        }
        params.put(item.getFieldName(), values);
    } else {
        log.debug("Item is a file upload");

        List<FileItem> values;
        if (files.get(item.getFieldName()) != null) {
      values = files.get(item.getFieldName());
        } else {
      values = new ArrayList<FileItem>();
        }

        values.add(item);
        files.put(item.getFieldName(), values);
    }
      }
  } catch (FileUploadException e) {
      e.printStackTrace();
      if (monitor != null)
View Full Code Here


      return null;
  }

  List<String> contentTypes = new ArrayList<String>(items.size());
  for (int i = 0; i < items.size(); i++) {
      FileItem fileItem = (FileItem) items.get(i);
      contentTypes.add(fileItem.getContentType());
  }

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

        FormData uploadItem = new FormData();
        GAV gav = new GAV( "org.kie.guvnor",
                           "guvnor-m2repo-editor-backend",
                           "0.0.1-SNAPSHOT" );
        uploadItem.setGav( gav );
        FileItem file = new TestFileItem();
        uploadItem.setFile( file );

        assert ( helperMethod.invoke( helper,
                                      uploadItem ).equals( "OK" ) );
    }
View Full Code Here

        // Set upload parameters
        upload.setSizeMax(-1);
   
        // Parse the request
        String war = null;
        FileItem warUpload = null;
        File xmlFile = null;
       
        // There is a possible race condition here. If liveDeploy is true it
        // means the deployer could start to deploy the app before we do it.
        synchronized(getLock()) {
            try {
                List items = upload.parseRequest(request);
           
                // Process the uploaded fields
                Iterator iter = items.iterator();
                while (iter.hasNext()) {
                    FileItem item = (FileItem) iter.next();
           
                    if (!item.isFormField()) {
                        if (item.getFieldName().equals("installWar") &&
                            warUpload == null) {
                            warUpload = item;
                        } else {
                            item.delete();
                        }
                    }
                }
                while(true) {
                    if (warUpload == null) {
View Full Code Here

                    "layoutEvents.no_files_uploaded", locale));
        }


        // This code finds the idField and the upload FileItems
        FileItem fi = null;
        FileItem imageFi = null;
        for (int i=0; i < lst.size(); i++) {
            fi = lst.get(i);
            String fieldName = fi.getFieldName();
            String fieldStr = fi.getString();
            if (fi.isFormField()) {
                formInput.put(fieldName, fieldStr);
                request.setAttribute(fieldName, fieldStr);
            //Debug.logVerbose("in uploadAndStoreImage, fieldName:" + fieldName + " fieldStr:" + fieldStr, "");
            }
            if (fieldName.equals(uploadField)) {
                imageFi = fi;
                //MimeType of upload file
                results.put("uploadMimeType", fi.getContentType());
            }
        }

        if (imageFi == null) {
            String errMsg = UtilProperties.getMessage(err_resource,
                    "layoutEvents.image_null", UtilMisc.toMap("imageFi", imageFi), locale);
            request.setAttribute("_ERROR_MESSAGE_", errMsg);
            //Debug.logWarning("[DataEvents.uploadImage] imageFi(" + imageFi + ") is null", module);
            return null;
        }

        byte[] imageBytes = imageFi.get();
        ByteBuffer byteWrap = ByteBuffer.wrap(imageBytes);
        results.put("imageData", byteWrap);
        results.put("imageFileName", imageFi.getName());

        //Debug.logVerbose("in uploadAndStoreImage, results:" + results, "");
        return results;
    }
View Full Code Here

                } catch (FileUploadException fue) {
                    request.setAttribute(FileUploadService.UPLOAD_EXCEPTION, fue);
                }

                for (int i = 0; i < itemsList.size(); i++) {
                    FileItem fileItem = (FileItem) itemsList.get(i);

                    String name = fileItem.getFieldName();
                    String value = null;

                    // Form fields are placed in the request parameter map,
                    // while file uploads are placed in the file item map.
                    if (fileItem.isFormField()) {

                        if (request.getCharacterEncoding() == null) {
                            value = fileItem.getString();

                        } else {
                            try {
                                value = fileItem.getString(request.getCharacterEncoding());

                            } catch (UnsupportedEncodingException ex) {
                                throw new RuntimeException(ex);
                            }
                        }
View Full Code Here

        upload.setRepositoryPath(tempdir.getCanonicalPath());
   
        // Parse the request
        String basename = null;
        String war = null;
        FileItem warUpload = null;
        try {
            List items = upload.parseRequest(request);
       
            // Process the uploaded fields
            Iterator iter = items.iterator();
            while (iter.hasNext()) {
                FileItem item = (FileItem) iter.next();
       
                if (!item.isFormField()) {
                    if (item.getFieldName().equals("deployWar") &&
                        warUpload == null) {
                        warUpload = item;
                    } else {
                        item.delete();
                    }
                }
            }
            while (true) {
                if (warUpload == null) {
View Full Code Here

   
        // Parse the request
        String basename = null;
        File appBaseDir = null;
        String war = null;
        FileItem warUpload = null;
        try {
            List items = upload.parseRequest(request);
       
            // Process the uploaded fields
            Iterator iter = items.iterator();
            while (iter.hasNext()) {
                FileItem item = (FileItem) iter.next();
       
                if (!item.isFormField()) {
                    if (item.getFieldName().equals("deployWar") &&
                        warUpload == null) {
                        warUpload = item;
                    } else {
                        item.delete();
                    }
                }
            }
            while (true) {
                if (warUpload == null) {
View Full Code Here

     * @return the newly created file item
     */
    public FileItem createItem(String fieldName, String contentType,
        boolean isFormField, String fileName) {

        FileItem result =
            new MemoryFileItem(fieldName, contentType, isFormField, fileName);
        return result;
    }
View Full Code Here

     */
    public void validate() {
        setError(null);

        if (isRequired()) {
            FileItem fileItem = getFileItem();
            if (fileItem == null || StringUtils.isBlank(fileItem.getName())) {
                setErrorMessage("file-required-error");
            }
        }
    }
View Full Code Here

TOP

Related Classes of org.apache.commons.fileupload.FileItem

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.