Package org.apache.commons.fileupload

Examples of org.apache.commons.fileupload.FileItemStream


    // Get the image representation
    try{
        ServletFileUpload upload = new ServletFileUpload();
        FileItemIterator iter = upload.getItemIterator(req);
        while(iter.hasNext()){
          FileItemStream imageItem = iter.next();
          InputStream imgStream = imageItem.openStream();
          byte[] data = IOUtils.toByteArray(imgStream);
          imgStream.close();
          if(!imageItem.isFormField() && data.length>0){
            log.info("Is a file: "+imageItem.getName());
            Blob imageBlob = new Blob(resizeImage(data));
            images.put(imageItem.getName(), imageBlob);
          }
        }
        ArticlesOAM oam = provider.get();
        UserService userService = UserServiceFactory.getUserService();
          User user = userService.getCurrentUser();
View Full Code Here


                fileUpload.setFileSizeMax(cfg.getFileUploadFileSizeMax());
            }
            try {
                FileItemIterator it = fileUpload.getItemIterator(request);
                while (it.hasNext()) {
                    FileItemStream fis = it.next();
                    if (fis.isFormField()) {
                        String s = Streams.asString(fis.openStream(), cfg.getCharset());
                        Object o = params.get(fis.getFieldName());
                        if (o == null) {
                            params.put(fis.getFieldName(), new String[]{s});
                        } else if (o instanceof String[]) {
                            String[] ss = (String[]) o;
                            String[] nss = new String[ss.length + 1];
                            System.arraycopy(ss, 0, nss, 0, ss.length);
                            nss[ss.length] = s;
                            params.put(fis.getFieldName(), nss);
                        }
                    } else if (!fis.getName().isEmpty()) {
                        FileExImpl fileEx = new FileExImpl(File.createTempFile("wfu", null));
                        Object o = params.get(fis.getFieldName());
                        if (o == null) {
                            params.put(fis.getFieldName(), new FileEx[]{fileEx});
                        } else if (o instanceof FileEx[]) {
                            FileEx[] ss = (FileEx[]) o;
                            FileEx[] nss = new FileEx[ss.length + 1];
                            System.arraycopy(ss, 0, nss, 0, ss.length);
                            nss[ss.length] = fileEx;
                            params.put(fis.getFieldName(), nss);
                        }
                        Streams.copy(fis.openStream(), new FileOutputStream(fileEx.getFile()), true);
                        fileEx.fileName = fis.getName();
                        fileEx.contentType = fis.getContentType();
                    }
                }
            } catch (FileUploadException e) {
                if (action instanceof FileUploadExceptionAware) {
                    ((FileUploadExceptionAware) action).setFileUploadException(e);
View Full Code Here

        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

   
    try {
      FileItemIterator i = new ServletFileUpload().getItemIterator(req);

      while (i.hasNext()) {
        FileItemStream item = i.next();
        InputStream stream = item.openStream();
        try {
          String randomId = UUID.randomUUID().toString()// cache ID
          byte[] rawData = FileUtil.toByteArray(stream)// cache data

          memcache.put(randomId, rawData);
          logger.info("Cached uploaded file id : " + randomId + " with size = " + rawData.length);
         
          CacheUploadResult result = AutoBeanUtil.newCacheUploadResult(Status.SUCCESS, randomId, item.getName(), rawData.length);
          resultStr = AutoBeanUtil.encode(CacheUploadResult.class, result);
        } finally {
          stream.close();
        }
      }
View Full Code Here

      // step1 : extract data from the request
      String fileName = null;
      byte[] rawData = null;
     
      while (i.hasNext()) {
        FileItemStream item = i.next();
        
        InputStream stream = item.openStream();
       
        byte [] content = FileUtil.toByteArray(stream);
       
        try {
          if (item.isFormField()) {  // filename         
            fileName = new String(content);
          } else // rawdata
            rawData = content;   
         
        } finally {
View Full Code Here

        // Parse the request
        try {
            FileItemIterator iter = upload.getItemIterator(request);
            while (iter.hasNext() == true) {
                FileItemStream item = iter.next();
                String name = item.getName();
                InputStream stream = item.openStream();
                if (item.isFormField() == false) {
                    ContentResource child = (ContentResource)
                            dir.createChild(name, ContentNode.Type.RESOURCE);

                    File tmp = File.createTempFile("contentupload", "tmp");
                    RunUtil.writeToFile(stream, tmp);
View Full Code Here

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

            while (iter.hasNext()) {
                FileItemStream item = iter.next();

                String name = item.getFieldName();
                log("Uploaf file: " + name);
                InputStream stream = item.openStream();


                // Process the input stream
                ByteArrayOutputStream out = new ByteArrayOutputStream();
                int len;
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

      ServletFileUpload upload = new ServletFileUpload();
      try {
        FileItemIterator iter = upload.getItemIterator(request);
        while (iter.hasNext()) {
          FileItemStream item = iter.next();
          String fieldName = item.getFieldName();
          InputStream stream = item.openStream();
          if (item.isFormField()) {
            inputParams.put(fieldName, new String[] { Streams.asString(stream, Encoding.CHARSET_UTF8_NAME) });
          } else {
            fileUploads.put(fieldName, IOHelpers.toByteArray(stream));
          }
        }
View Full Code Here

        ServletFileUpload upload = new ServletFileUpload();

        FileItemIterator iter = upload.getItemIterator(request);
        while (iter.hasNext()) {
            FileItemStream item = iter.next();
            String name = item.getFieldName().toLowerCase();
            InputStream stream = item.openStream();
            if (item.isFormField()) {
                if (name.equals("url")) {
                    url = Streams.asString(stream);
                } else {
                    options.put(name, Streams.asString(stream));
                }
            } else {
                String fileName = item.getName().toLowerCase();
                try {
                    ProjectManager.singleton.importProject(projectID, stream, !fileName.endsWith(".tar"));
                } finally {
                    stream.close();
                }
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.