Package org.apache.commons.fileupload

Examples of org.apache.commons.fileupload.FileItem


            // Parse the request
            List<FileItem> items = upload.parseRequest(request);
            Iterator<FileItem> iter = items.iterator();
            IVResource userDirectory = user.getResource(path);
            while (iter.hasNext()) {
                FileItem item = iter.next();

                if (!item.isFormField()) {
                    String fileName = item.getName();
                    InputStream is = new BufferedInputStream(item.getInputStream());;
                    OutputStream os = null;
                    byte[] buffer = new byte[8192];

                try {
                      if(explodeZip && ("application/zip".equals(item.getContentType()) || fileName.endsWith(".zip"))){
              ZipInputStream zis = new ZipInputStream(is);
              ZipEntry entry;
                int bytesIn;
              is = zis;
           
View Full Code Here


    // Parse the request
    List items = upload.parseRequest(req);
    Iterator iter = items.iterator();
    while (iter.hasNext()) {
        FileItem item = (FileItem) iter.next();

        // If its a form field, put it in our parameter map
        if (item.isFormField()) {
          MultiMapSolrParams.addParam(
            item.getFieldName(),
            item.getString(), params.getMap() );
        }
        // Add the stream
        else {
            System.out.println(item.getFieldName()+"==="+item.getSize());
          streams.add( new FileItemContentStream( item ) );
        }
    }
    return params;
  }
View Full Code Here

        prod.setProductId("myfish");
        prod.setDescription("My fish");
        prod.setName("my fish");

        FileItem fi = createMock(FileItem.class);
        expect(fi.getName()).andReturn("c:\\test\\pic.gif");
        expect(fi.getInputStream()).andAnswer(new IAnswer<InputStream>() {
            public InputStream answer() throws Throwable {
                return new FileInputStream(srcfile);
            }
        });
        replay(fi);
View Full Code Here

    try {
      File file = null;
     
      Iterator<?> iter = items.iterator();
      while (iter.hasNext()) {
          FileItem item = (FileItem) iter.next();
 
          if (item.isFormField()) {
              processFormField(item);
          }
          else {
              file = processUploadedFile(request, item);
          }
View Full Code Here

    try {
      File file = null;
     
      Iterator<?> iter = items.iterator();
      while (iter.hasNext()) {
          FileItem item = (FileItem) iter.next();
 
          if (item.isFormField()) {
            fields.put(item.getFieldName(), item.getString());
          }
          else {
              file = processUploadedFile(request, item);
          }
      }
View Full Code Here

      public FileCleaningTracker getFileCleaningTracker()
      {
        return new FileCleanerTrackerAdapter(fileUploadCleaner);
      }
    };
    FileItem fileItem = itemFactory.createItem("dummyFieldName",
        "text/java", false, "FileUploadTest.java");
    // Initialize the upload
    fileItem.getOutputStream();

    // Get the internal list out
    Field inputStreamsField = FileUpload.class.getDeclaredField("inputStreamsToClose");
    inputStreamsField.setAccessible(true);
View Full Code Here

            if (multipartRequest != null)
            {
                MultipartRequestWrapper mpReq = (MultipartRequestWrapper)multipartRequest;

                String paramName = uiComponent.getClientId(facesContext);
                FileItem fileItem = mpReq.getFileItem(paramName);
                if (fileItem != null)
                {
                    try{
                        UploadedFile upFile;
                        String implementation = ((HtmlInputFileUpload) uiComponent).getStorage();
View Full Code Here

        int count = Tapestry.size(parts);

        for (int i = 0; i < count; i++)
        {
            FileItem uploadItem = (FileItem) parts.get(i);

            if (uploadItem.isFormField())
            {
                try
                {
                    String name = uploadItem.getFieldName();
                    String value;
                    if (encoding == null)
                        value = uploadItem.getString();
                    else
                        value = uploadItem.getString(encoding);
                       
                    ValuePart valuePart = (ValuePart) partMap.get(name);
                    if (valuePart != null)
                    {
                        valuePart.add(value);
                    }
                    else
                    {
                        valuePart = new ValuePart(value);
                        partMap.put(name, valuePart);
                    }
                }
                catch (UnsupportedEncodingException ex)
                {
                    throw new ApplicationRuntimeException(
                        Tapestry.format("illegal-encoding", encoding),
                        ex);
                }
            }
            else
            {
                UploadPart uploadPart = new UploadPart(uploadItem);

                partMap.put(uploadItem.getFieldName(), uploadPart);
            }
        }

    }
View Full Code Here

  private String contentType;
  private boolean transientValue;

  public void validate(FacesContext context, UIComponent component, Object value) throws ValidatorException {
    if (value != null && component instanceof UIFileInput) {
      FileItem file = (FileItem) value;
      if (maxSize != null && file.getSize() > maxSize) {
        Object[] args = {maxSize,  component.getId()};
        FacesMessage facesMessage = MessageFactory.createFacesMessage(context,
            SIZE_LIMIT_MESSAGE_ID, FacesMessage.SEVERITY_ERROR, args);
        throw new ValidatorException(facesMessage);
      }
      // Check only a valid file
      if (file.getSize() > 0 && contentType != null
          && !ContentType.valueOf(contentType).match(ContentType.valueOf(file.getContentType()))) {
        ContentType expectedContentType = ContentType.valueOf(contentType);
        Object [] args = {expectedContentType, component.getId()};
        FacesMessage facesMessage = MessageFactory.createFacesMessage(context,
            CONTENT_TYPE_MESSAGE_ID, FacesMessage.SEVERITY_ERROR, args);
        throw new ValidatorException(facesMessage);
View Full Code Here

           lst = UtilGenerics.checkList(fu.parseRequest(request));
        } catch (FileUploadException e4) {
            return e4.getMessage();
        }
               
        FileItem fi = null;
        FileItem imageFi = null;
        byte[] imageBytes = {};
        for (int i=0; i < lst.size(); i++) {
            fi = lst.get(i);
            String fieldName = fi.getFieldName();
            if (fi.isFormField()) {
                String fieldStr = fi.getString();
                formInput.put(fieldName, fieldStr);
            } else if (fieldName.startsWith("imageData")) {
                Map<String, Object> passedParams = FastMap.newInstance();
                Map<String, Object> contentLength = FastMap.newInstance();
                if(josonMap == null){
                     josonMap = FastList.newInstance();
                }
                imageFi = fi;
                String fileName = fi.getName();
                String contentType = fi.getContentType();
                imageBytes = imageFi.get();
                ByteBuffer byteWrap = ByteBuffer.wrap(imageBytes);
                passedParams.put("userLogin", userLogin);
                passedParams.put("productId", formInput.get("productId"));
                passedParams.put("productContentTypeId", "IMAGE");
                passedParams.put("_uploadedFile_fileName", fileName);
                passedParams.put("_uploadedFile_contentType", contentType);
                passedParams.put("uploadedFile", byteWrap);
                passedParams.put("imageResize", formInput.get("imageResize"));
                contentLength.put("imageSize", imageFi.getSize());
                josonMap.add(contentLength);
               
                if (passedParams.get("productId") != null) {
                    try {
                        dispatcher.runSync("addMultipleuploadForProduct", passedParams);
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.