Package org.apache.commons.fileupload

Examples of org.apache.commons.fileupload.FileItemStream


      uploadParser.setSizeMax(uploadSize);
      // Parse the request
      try {
        FileItemIterator iter = uploadParser.getItemIterator(ureq.getHttpReq());
        while (iter.hasNext()) {
          FileItemStream item = iter.next();
          String itemName = item.getFieldName();
          InputStream itemStream = item.openStream();
          if (item.isFormField()) {
            // Normal form item
            // analog to ureq.getParameter in non-multipart mode
            String value = Streams.asString(itemStream, "UTF-8");
            addRequestParameter(itemName, value);
          } else {
            // File item, store it to temp location
            String fileName = item.getName();
            // Cleanup IE filenames that are absolute
            int slashpos = fileName.lastIndexOf("/");
            if (slashpos != -1) fileName = fileName.substring(slashpos + 1);
            slashpos = fileName.lastIndexOf("\\");
            if (slashpos != -1) fileName = fileName.substring(slashpos + 1);

            File tmpFile = new File(WebappHelper.getUserDataRoot() + "/tmp/" + CodeHelper.getGlobalForeverUniqueID());
            try {
              FileUtils.save(itemStream, tmpFile);
              // Only save non-empty file transfers, ignore empty transfers
              // (e.g. already submitted in a previous form submit, not an error!)
              if (tmpFile.length() > 0) {
                // Save file and also original file name
                requestMultipartFiles.put(itemName, tmpFile);
                requestMultipartFileNames.put(itemName, fileName);
                requestMultipartFileMimeTypes.put(itemName, item.getContentType());
              } else {
                if (tmpFile.exists()) tmpFile.delete();
              }
            } catch (OLATRuntimeException e) {
              // Could not save stream for whatever reason, cleanup temp file and delegate exception
View Full Code Here


        FileItemIterator iter;
        try {
          iter = upload.getItemIterator(request);
          InputStream stream = null;
          while (iter.hasNext()) {
            FileItemStream item = iter.next();
            stream = item.openStream();
            if (item.isFormField()) {
              parameters.put(item.getFieldName(),
                Streams.asString(stream, "UTF-8"));
            } else {
              files.add(new FileItem(item,
                StreamUtil.readFileStream(stream)));
            }
View Full Code Here

    List<UploadItem> uploadItems = new ArrayList<UploadItem>();
    try {
      FileItemIterator iter;
      try {
        iter = upload.getItemIterator(request);
        FileItemStream imageFileItem = null;
        String folder = null;
        InputStream stream = null;
        InputStream filestream = null;
        byte[] fileData = null;
        parameters.put(IMAGE_UPLOAD_PAGE_ID,
            (String)session.getAttribute(
                IMAGE_UPLOAD_PAGE_ID));
        if (request.getParameter("CKEditorFuncNum") != null) {
          ckeditorFuncNum = request.getParameter("CKEditorFuncNum");
        }
        while (iter.hasNext()) {
          FileItemStream item = iter.next();
          stream = item.openStream();
          if (item.isFormField()) {
            parameters.put(item.getFieldName(),
                Streams.asString(stream, "UTF-8"));
          } else {
            UploadItem uploadItem = new UploadItem();
            uploadItem.item = item;
            uploadItem.data = StreamUtil.readFileStream(stream);
View Full Code Here

            throws ServletException, IOException {
        ServletFileUpload upload = new ServletFileUpload();
        try {
            FileItemIterator iterator = upload.getItemIterator(req);
            while (iterator.hasNext()) {
                FileItemStream item = iterator.next();
                String name = item.getName();
                if (name == null) {
                    continue;
                }
                if (!Arrays.asList("jpeg", "jpg", "bmp", "png", "gif").contains(PhotoService.getExtension(name))) {
                    continue;
                }
                InputStream stream = item.openStream();
                ByteArrayOutputStream out = new ByteArrayOutputStream();
                int len;
                byte[] buffer = new byte[8192];
                while ((len = stream.read(buffer, 0, buffer.length)) != -1) {
                    out.write(buffer, 0, len);
View Full Code Here

        // Parse the request
        try {
            FileItemIterator iter = upload.getItemIterator(request);
            while (iter.hasNext() == true) {
                FileItemStream item = iter.next();
                InputStream stream = item.openStream();
                if (item.isFormField() == false) {
                    /*
                     * The name given should have a .jar extension. Check this here. If
                     * not, return an error. If so, parse out just the module name.
                     */
                    String moduleJar = item.getName();
                    if (moduleJar.endsWith(".jar") == false) {
                        /* Log an error to the log and write an error message back */
                        LOGGER.warning("Upload is not a jar file " + moduleJar);
                        String msg = "The file " + moduleJar + " needs to be" +
                                " a jar file. Please try again.";
View Full Code Here

    ServletFileUpload upload = new ServletFileUpload();
    upload.setSizeMax(50000);
    try {
      FileItemIterator iterator = upload.getItemIterator(req);
      while (iterator.hasNext()) {
        FileItemStream item = iterator.next();
        InputStream in = item.openStream();
        if (item.isFormField()) {
          String fieldName = item.getFieldName();
          if (fieldName.equals("phoneNumber")) {
            phoneNumber = Streams.asString(in, "UTF-8");
          } else if (fieldName.equals("defaultCountry")) {
            defaultCountry = Streams.asString(in).toUpperCase();
          } else if (fieldName.equals("languageCode")) {
View Full Code Here

try {
    FileItemIterator iter = upload.getItemIterator(req);
//List<FileItem> items = upload.parseRequest(req);

while (iter.hasNext()) {
       FileItemStream item = iter.next();
//for (int ct = 0;ct < items.size();ct++){

//         FileItem item = (FileItem)items.get(ct);

        String name = item.getName();
        //(name + " jiql UREEAD 1aay " + item.isFormField() + ":" + name.equals("directValues"));

InputStream stream = item.openStream();
//InputStream stream = item.getInputStream();

////(name + " jiql UREEAD 1 " + stream.available());
//byte[] b = StreamUtil.readBytes(stream);
View Full Code Here

      upload.setSizeMax(maxSize);

      FileItemIterator iterator = upload.getItemIterator(request);

      while (iterator.hasNext()) {
        FileItemStream itemStream = iterator.next();
        InputStream in = itemStream.openStream();

        if (LOG.isDebugEnabled())
          LOG.debug("Found item " + itemStream.getFieldName());
        if (itemStream.isFormField()) {
          LOG.debug("Item is a normal form field");
          List<String> values;
          if (params.get(itemStream.getFieldName()) != null) {
            values = params.get(itemStream.getFieldName());
          } else {
            values = new ArrayList<String>();
          }

          values.add(IOUtils.toString(in, "ISO-8859-1"));
          params.put(itemStream.getFieldName(), values);
        } else {
          LOG.debug("Item is a file upload");

          // Skip file uploads that don't have a file name - meaning
          // that no file was selected.
          if (itemStream.getName() == null
              || itemStream.getName().trim().length() < 1) {
            LOG.debug("No file has been uploaded for the field: "
                + itemStream.getFieldName());
            continue;
          }

          List<FileItemStream> values;
          List<String> fileValues;
          if (files.get(itemStream.getFieldName()) != null) {
            values = files.get(itemStream.getFieldName());
            fileValues = fileContents
                .get(itemStream.getFieldName());
          } else {
            values = new ArrayList<FileItemStream>();
            fileValues = new ArrayList<String>();
          }

          values.add(itemStream);
          fileValues.add(IOUtils.toString(itemStream.openStream(),
              "ISO-8859-1"));
          files.put(itemStream.getFieldName(), values);
          fileContents.put(itemStream.getFieldName(), fileValues);
        }
      }
    } catch (FileUploadException e) {
      LOG.error("Unable to parse request", e);
      errors.add(e.getMessage());
View Full Code Here

            try {
                resp.setContentType("text/plain");
                FileItemIterator iterator = upload.getItemIterator(req);

                while (iterator.hasNext()) {
                    FileItemStream item = iterator.next();
                   InputStream stream = item.openStream();
                  if (item.isFormField()) {
                        System.out.println("Got a form field: " + item.getFieldName()  + " " +item);
                 } else{
                       System.out.println("Got an uploaded file: " + item.getFieldName() +
                                  ", name = " + item.getName());
                        int len;
                        byte[] buffer = new byte[8192];
                        while ((len = stream.read(buffer, 0, buffer.length)) != -1) {
                          //TODO : send data to service/dossier-to-json
                          //resp.getOutputStream().write(buffer, 0, len);
View Full Code Here

            Lang lang = null ;
            int tripleCount = 0 ;
           
            FileItemIterator iter = upload.getItemIterator(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) ;
                            }
                            gn = Node.createURI(graphName) ;
                        }
                    }
                    else if ( fieldName.equals(HttpNames.paramDefaultGraphURI) )
                        graphName = null ;
                    else
                        // Add file type?
                        log.info(format("[%d] Upload: Field="+fieldName+" - ignored")) ;
                } 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 = FusekiLib.langFromContentType(ct.getContentType()) ;
                    if ( lang == null )
                        lang = Lang.guess(name) ;
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.