Package org.apache.commons.fileupload

Examples of org.apache.commons.fileupload.FileItemStream


        int tripleCount = 0 ;

        try {
            FileItemIterator iter = upload.getItemIterator(action.request);
            while (iter.hasNext()) {
                FileItemStream item = iter.next();
                String fieldName = item.getFieldName();
                InputStream stream = item.openStream();
                if (item.isFormField())
                {
                    // Graph name.
                    String value = Streams.asString(stream, "UTF-8") ;
                    if ( fieldName.equals(HttpNames.paramGraph) )
                    {
                        graphName = value ;
                        if ( graphName != null && ! graphName.equals(HttpNames.valueDefault) )
                        {
                            IRI iri = IRIResolver.parseIRI(value) ;
                            if ( iri.hasViolation(false) )
                                errorBadRequest("Bad IRI: "+graphName) ;
                            if ( iri.getScheme() == null )
                                errorBadRequest("Bad IRI: no IRI scheme name: "+graphName) ;
                            if ( iri.getScheme().equalsIgnoreCase("http") || iri.getScheme().equalsIgnoreCase("https"))
                            {
                                // Redundant??
                                if ( iri.getRawHost() == null )
                                    errorBadRequest("Bad IRI: no host name: "+graphName) ;
                                if ( iri.getRawPath() == null || iri.getRawPath().length() == 0 )
                                    errorBadRequest("Bad IRI: no path: "+graphName) ;
                                if ( iri.getRawPath().charAt(0) != '/' )
                                    errorBadRequest("Bad IRI: Path does not start '/': "+graphName) ;
                            }
                        }
                    }
                    else if ( fieldName.equals(HttpNames.paramDefaultGraphURI) )
                        graphName = null ;
                    else
                        // Add file type?
                        log.info(format("[%d] Upload: Field=%s ignored", action.id, fieldName)) ;
                } else {
                    // Process the input stream
                    name = item.getName() ;
                    if ( name == null || name.equals("") || name.equals("UNSET FILE NAME") )
                        errorBadRequest("No name for content - can't determine RDF syntax") ;

                    String contentTypeHeader = item.getContentType() ;
                    ct = ContentType.parse(contentTypeHeader) ;

                    lang = WebContent.contentTypeToLang(ct.getContentType()) ;
                    if ( lang == null )
                        lang = RDFLanguages.filenameToLang(name) ;
View Full Code Here


            ServletFileUpload upload = new ServletFileUpload();

            try {
                FileItemIterator iter = upload.getItemIterator(req);
                while (iter.hasNext()) {
                    FileItemStream item = iter.next();
                    String name = item.getName();
                    InputStream input = item.openStream();

                    // Handle a form field.
                    if (item.isFormField()) {
                        System.out.println("name=" + name + ", value=" + Streams.asString(input));
                    }

                    // Handle a multi-part MIME encoded file.
                    else {
View Full Code Here

    HashMap<String, ByteArrayHolder> uploadContents = new HashMap<String, ByteArrayHolder>();
    HashMap<String, String> regularProperties = new HashMap<String, String>();
    try {
      iter = upload.getItemIterator(req);
      while (iter.hasNext()) {
        FileItemStream item = iter.next();
        String fieldName = item.getFieldName();
        InputStream stream = item.openStream();
        if (item.isFormField()) {
          String value = Streams.asString(stream, "UTF-8");
          System.out.println("Form field " + fieldName + " with value "
              + value + " detected.");
          if(KEY_FIELD.equals(fieldName)){
            key = value;
          } else if(PARENT_KEY_FIELD.equals(fieldName)) {
            parentKey = value;
          } else if(KIND_FIELD.equals(fieldName)){
            kind = value;
          } else if(fieldName.startsWith(UploadStatus.FLAG_PREFIX)){
            String name = fieldName.substring(UploadStatus.FLAG_PREFIX.length());
            UploadStatus status = UploadStatus.valueOf(UploadStatus.class, value);
            uploadStatuses.put(name, status);
          } else {
            regularProperties.put(fieldName, value);
          }
        } else {
          System.out.println("File field " + fieldName
              + " with file name " + item.getName()
              + " detected.");
          byte[] content = IOUtils.toByteArray(stream);
          uploadContents.put(fieldName, new ByteArrayHolder(content));
        }
      }
View Full Code Here

      upload.setSizeMax(maxUploadSize);
      upload.setProgressListener(listener);
     
      FileItemIterator iter = upload.getItemIterator(request);
      while (iter.hasNext()) {
          FileItemStream item = iter.next();
          String name = item.getFieldName();
          InputStream stream = item.openStream();
          if (item.isFormField()) {
            String value = Streams.asString(stream);

            logger.info("Upload "+name+":"+value);
           
            if( "progressId".equals(name) ) {
              progressId = value;
              listener.setProgressId(value);
            }
           
            // Add parameter to map
            List<String> paramList = parameterMap.get(name);
            if( null == paramList ) {
              paramList = new Vector<String>();
              parameterMap.put(name,paramList);
            }
            paramList.add(value);
           
          } else {
           
            LoadedFileImpl loadedFile = new LoadedFileImpl();
            loadedFile.setParameterName(name);

            // Get original filename
            String fileName = item.getName();
              if (fileName != null) {
                fileName = fileName.trim();
                if( 0 == fileName.length() ) {
                  fileName = null;
                } else {
View Full Code Here

public class BinaryUploader {

  public static final State save(HttpServletRequest request,
      Map<String, Object> conf) {
    FileItemStream fileStream = null;
    boolean isAjaxUpload = request.getHeader( "X_Requested_With" ) != null;

    if (!ServletFileUpload.isMultipartContent(request)) {
      return new BaseState(false, AppInfo.NOT_MULTIPART_CONTENT);
    }

    ServletFileUpload upload = new ServletFileUpload(
        new DiskFileItemFactory());

        if ( isAjaxUpload ) {
            upload.setHeaderEncoding( "UTF-8" );
        }

    try {
      FileItemIterator iterator = upload.getItemIterator(request);

      while (iterator.hasNext()) {
        fileStream = iterator.next();

        if (!fileStream.isFormField())
          break;
        fileStream = null;
      }

      if (fileStream == null) {
        return new BaseState(false, AppInfo.NOTFOUND_UPLOAD_DATA);
      }

      String savePath = (String) conf.get("savePath");
      String originFileName = fileStream.getName();
      String suffix = FileType.getSuffixByFilename(originFileName);

      originFileName = originFileName.substring(0,
          originFileName.length() - suffix.length());
      savePath = savePath + suffix;

      long maxSize = ((Long) conf.get("maxSize")).longValue();

      if (!validType(suffix, (String[]) conf.get("allowFiles"))) {
        return new BaseState(false, AppInfo.NOT_ALLOW_FILE_TYPE);
      }

      savePath = PathFormat.parse(savePath, originFileName);

      String physicalPath = (String) conf.get("rootPath") + savePath;

      InputStream is = fileStream.openStream();
      State storageState = StorageManager.saveFileByInputStream(is,
          physicalPath, maxSize);
      is.close();

      if (storageState.isSuccess()) {
View Full Code Here

      // Parse the request
      FileItemIterator iter;
      try {
        iter = upload.getItemIterator(req);
        while (iter.hasNext()) {
          FileItemStream item = iter.next();
          String name = item.getFieldName();
          InputStream stream = item.openStream();
          if (item.isFormField()) {
            log.debug("Form field " + name + " with value " + Streams.asString(stream) + " detected.");
          } else {
            log.debug("File field " + name + " with file name " + item.getName() + " detected.");

            File file = new File(DEFAULT_UPLOADS_DIR + "/" + item.getName());
            // Process the input stream
            FileOutputStream fos = new FileOutputStream(file);
            copyInputStreamToOuputStream(stream, fos);
            files.add(file);
          }
View Full Code Here

        org.apache.commons.fileupload.FileItemIterator it = null;
        try {
            it = upload.getItemIterator(request);

            while (it.hasNext()) {
                FileItemStream stream = it.next();
                InputStream input = stream.openStream();

                // NOTE: we are going to pull the entire stream into memory
                // this will NOT work if we have huge scripts, but we expect these to be measured in KBs, not MBs or larger
                byte[] uploadedBytes = getBytesFromInputStream(input);
                input.close();
View Full Code Here

      upload.setSizeMax(maxUploadSize);
      upload.setProgressListener(listener);
     
      FileItemIterator iter = upload.getItemIterator(request);
      while (iter.hasNext()) {
          FileItemStream item = iter.next();
          String name = item.getFieldName();
          InputStream stream = item.openStream();
          if (item.isFormField()) {
            String value = Streams.asString(stream);

            logger.info("Upload "+name+":"+value);
           
            if( "progressId".equals(name) ) {
              progressId = value;
              listener.setProgressId(value);
            }
           
            // Add parameter to map
            List<String> paramList = parameterMap.get(name);
            if( null == paramList ) {
              paramList = new Vector<String>();
              parameterMap.put(name,paramList);
            }
            paramList.add(value);
           
          } else {
           
            LoadedFileImpl loadedFile = new LoadedFileImpl();
            loadedFile.setParameterName(name);

            // Get original filename
            String fileName = item.getName();
              if (fileName != null) {
                fileName = fileName.trim();
                if( 0 == fileName.length() ) {
                  fileName = null;
                } else {
View Full Code Here

      upload.setSizeMax(maxUploadSize);
      upload.setProgressListener(listener);
     
      FileItemIterator iter = upload.getItemIterator(request);
      while (iter.hasNext()) {
          FileItemStream item = iter.next();
          String name = item.getFieldName();
          InputStream stream = item.openStream();
          if (item.isFormField()) {
            String value = Streams.asString(stream);

            logger.info("Upload "+name+":"+value);
           
            if( "progressId".equals(name) ) {
              progressId = value;
              listener.setProgressId(value);
            } else {
              // Add parameter to map
              List<String> paramList = parameterMap.get(name);
              if( null == paramList ) {
                paramList = new Vector<String>();
                parameterMap.put(name,paramList);
              }
              paramList.add(value);
            }
           
          } else {
           
            LoadedFileImpl loadedFile = new LoadedFileImpl();
            loadedFile.setParameterName(name);

            // Get original filename
            String fileName = item.getName();
              if (fileName != null) {
                fileName = fileName.trim();
                if( 0 == fileName.length() ) {
                  fileName = null;
                } else {
View Full Code Here

      private PotentialFile getNext() throws FileUploadException, IOException {
        PotentialFile next = null;

        while (delegate.hasNext()) {
          FileItemStream stream = delegate.next();

          if (!stream.isFormField()) {
            UploadedFile file = new UploadedFileApacheCommons(stream);
            next = new PotentialFileSucceeded(file);
            break;
          } else {
            UploadedFormFieldApacheCommons field = new UploadedFormFieldApacheCommons(stream);
View Full Code Here

TOP

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

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.