Package org.apache.commons.fileupload

Examples of org.apache.commons.fileupload.FileUpload


        response.setContentType("text/html; charset=" + charset);

        String message = "";

        // Create a new file upload handler
        FileUpload upload = new FileUpload();

        // Get the tempdir
        File tempdir = (File) getServletContext().getAttribute
            ("javax.servlet.context.tempdir");
        // Set upload parameters
        upload.setSizeMax(-1);
        upload.setRepositoryPath(tempdir.getCanonicalPath());
   
        // Parse the request
        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();
View Full Code Here


        // Get the app config for the current request.
        ModuleConfig ac = (ModuleConfig) request.getAttribute(
                Globals.MODULE_KEY);

        // Create and configure a FileUpload instance.
        FileUpload upload = new FileUpload();
        // Set the maximum size before a FileUploadException will be thrown.
        upload.setSizeMax((int) getSizeMax(ac));
        // Set the maximum size that will be stored in memory.
        upload.setSizeThreshold((int) getSizeThreshold(ac));
        // Set the the location for saving data on disk.
        upload.setRepositoryPath(getRepositoryPath(ac));

        // Create the hash tables to be populated.
        elementsText = new Hashtable();
        elementsFile = new Hashtable();
        elementsAll = new Hashtable();

        // Parse the request into file items.
        List items = null;
        try {
            items = upload.parseRequest(request);
        } catch (FileUploadException e) {
            // Special handling for uploads that are too big.
            if (e.getMessage().endsWith("size exceeds allowed range")) {
                request.setAttribute(
                        MultipartRequestHandler.ATTRIBUTE_MAX_LENGTH_EXCEEDED,
View Full Code Here

        request.setAttribute(PART_MAP_ATTRIBUTE_NAME, partMap);

        // FileUpload is not quite threadsafe, so we create a new instance
        // for each request.

        FileUpload upload = new FileUpload();

        List parts = null;

        try
        {
            parts = upload.parseRequest(request, _thresholdSize, _maxSize, _repositoryPath);
        }
        catch (FileUploadException ex)
        {
            throw new ApplicationRuntimeException(
                Tapestry.format("DefaultMultipartDecoder.unable-to-decode", ex.getMessage()),
View Full Code Here

      try
      {
         if (FileUpload.isMultipartContent(requestContext))
         {
            // content is multipart, we need to parse it (that includes form parameters)
            FileUpload upload = new FileUpload();
            FileItemIterator iter = upload.getItemIterator(requestContext);
            List<UploadContext> uploadContexts = new ArrayList<UploadContext>(7);
            List<NamedString> formParameters = new ArrayList<NamedString>(7);
            while (iter.hasNext())
            {
               FileItemStream item = iter.next();
View Full Code Here

        // Get the app config for the current request.
        ApplicationConfig ac = (ApplicationConfig) request.getAttribute(
                Action.APPLICATION_KEY);

        // Create and configure a FileUpload instance.
        FileUpload upload = new FileUpload();
        // Set the maximum size before a FileUploadException will be thrown.
        upload.setSizeMax((int) getSizeMax(ac));
        // Set the maximum size that will be stored in memory.
        upload.setSizeThreshold(getSizeThreshold(ac));
        // Set the the location for saving data on disk.
        upload.setRepositoryPath(getRepositoryPath(ac));

        // Create the hash tables to be populated.
        elementsText = new Hashtable();
        elementsFile = new Hashtable();
        elementsAll = new Hashtable();

        // Parse the request into file items.
        List items = null;
        try {
            items = upload.parseRequest(request);
        } catch (FileUploadException e) {
            // Special handling for uploads that are too big.
            if (e.getMessage().endsWith("size exceeds allowed range")) {
                request.setAttribute(
                        MultipartRequestHandler.ATTRIBUTE_MAX_LENGTH_EXCEEDED,
View Full Code Here

        response.setContentType("text/html; charset=" + charset);

        String message = "";

        // Create a new file upload handler
        FileUpload upload = new FileUpload();

        // Get the tempdir
        File tempdir = (File) getServletContext().getAttribute
            ("javax.servlet.context.tempdir");
        // Set upload parameters
        upload.setSizeMax(-1);
        upload.setRepositoryPath(tempdir.getCanonicalPath());
   
        // Parse the request
        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();
View Full Code Here

        // Get the app config for the current request.
        ModuleConfig ac = (ModuleConfig) request.getAttribute(
                Globals.MODULE_KEY);

        // Create and configure a FileUpload instance.
        FileUpload upload = new FileUpload();
        // Set the maximum size before a FileUploadException will be thrown.
        upload.setSizeMax((int) getSizeMax(ac));
        // Set the maximum size that will be stored in memory.
        upload.setSizeThreshold(getSizeThreshold(ac));
        // Set the the location for saving data on disk.
        upload.setRepositoryPath(getRepositoryPath(ac));

        // Create the hash tables to be populated.
        elementsText = new Hashtable();
        elementsFile = new Hashtable();
        elementsAll = new Hashtable();

        // Parse the request into file items.
        List items = null;
        try {
            items = upload.parseRequest(request);
        } catch (FileUploadException e) {
            // Special handling for uploads that are too big.
            if (e.getMessage().endsWith("size exceeds allowed range")) {
                request.setAttribute(
                        MultipartRequestHandler.ATTRIBUTE_MAX_LENGTH_EXCEEDED,
View Full Code Here

      {
         if (FileUpload.isMultipartContent(requestContextWrapper))
         {
            result = new MultiPartResult();
            // content is multipart, we need to parse it (that includes form parameters)
            FileUpload upload = new FileUpload();
            FileItemIterator iter = upload.getItemIterator(requestContextWrapper);
            List<UploadContext> uploadContexts = new ArrayList<UploadContext>(7);
            List<NamedString> formParameters = new ArrayList<NamedString>(7);
            while (iter.hasNext())
            {
               FileItemStream item = iter.next();
View Full Code Here

        response.setContentType("text/html; charset=" + charset);

        String message = "";

        // Create a new file upload handler
        FileUpload upload = new FileUpload();

        // Get the tempdir
        File tempdir = (File) getServletContext().getAttribute
            ("javax.servlet.context.tempdir");
        // Set upload parameters
        upload.setSizeMax(-1);
        upload.setRepositoryPath(tempdir.getCanonicalPath());
   
        // Parse the request
        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();
View Full Code Here

  private FileUploadListener fileUploadListener;

  @Override
  public MultipartHttpServletRequest resolveMultipart(HttpServletRequest request) throws MultipartException {
    String encoding = determineEncoding(request);
    FileUpload fileUpload = prepareFileUpload(encoding);
    if (fileUploadListener != null) {
      fileUpload.setProgressListener(fileUploadListener);
      request.getSession(false).setAttribute("upload_listener", fileUploadListener);
    }
    try {
      List fileItems = ((ServletFileUpload) fileUpload).parseRequest(request);
      MultipartParsingResult parsingResult = parseFileItems(fileItems, encoding);
      Map<String, String> multipartContentTypes = new HashMap<String, String>();
      for (List<MultipartFile> files : parsingResult.getMultipartFiles().values()) {
        for (MultipartFile f : files) {
          multipartContentTypes.put(f.getName(), f.getContentType());
        }
      }
      return new DefaultMultipartHttpServletRequest(request, parsingResult.getMultipartFiles(), parsingResult.getMultipartParameters(), multipartContentTypes);
    }
    catch (FileUploadBase.SizeLimitExceededException ex) {
      throw new MaxUploadSizeExceededException(fileUpload.getSizeMax(), ex);
    }
    catch (FileUploadException ex) {
      throw new MultipartException("Could not parse multipart servlet request", ex);
    }
  }
View Full Code Here

TOP

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

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.