Package org.apache.commons.fileupload.servlet

Examples of org.apache.commons.fileupload.servlet.ServletFileUpload


    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws IOException {
        if (ServletFileUpload.isMultipartContent(request)) {
            User user = Common.getUser(request);
            GraphicalView view = GraphicalViewsCommon.getUserEditView(user);

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

            List<FileItem> items;
            try {
                items = upload.parseRequest(request);
            }
            catch (Exception e) {
                throw new RuntimeException(e);
            }
View Full Code Here


    // Set factory constraints
    // TODO - configure factory.setSizeThreshold(yourMaxMemorySize);
    // TODO - configure factory.setRepository(yourTempDirectory);

    // Create a new file upload handler
    ServletFileUpload upload = new ServletFileUpload(factory);
    upload.setSizeMax( uploadLimitKB*1024 );

    // 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
View Full Code Here

      throw new IOException("Unable to mkdirs to " + repository.getAbsolutePath());
    }

    fileItemsFactory = setupFileItemFactory(repository, context);

        ServletFileUpload upload = new ServletFileUpload(fileItemsFactory);
        List<FileItem> formFileItems = upload.parseRequest(request);

    parseFormFields(formFileItems);

    if (files.isEmpty())
    {
View Full Code Here

    private static final long serialVersionUID = 1264570282519238586L;

    @Override
    protected void doPost(HttpServletRequest req, final HttpServletResponse resp)
            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;
View Full Code Here

import org.apache.commons.fileupload.servlet.ServletFileUpload;

public class UploadFileUtils {

  public static FileItem getUploadFile(HttpServletRequest request, String file) throws Exception {
    ServletFileUpload fileUpload = new ServletFileUpload(new DiskFileItemFactory());
    List<FileItem> list = fileUpload.parseRequest(request);
    for(FileItem fileItem: list) {
      if (fileItem.getFieldName().equals(file)) {
        return fileItem;
      }
    }
View Full Code Here

        FileItemFactory factory = new DiskFileItemFactory();
       
        logger.debug("factory=" + factory);
       
        // upload handler
        ServletFileUpload upload = new ServletFileUpload(factory);
        logger.debug("upload=" + upload);
       
        String nameValue = "";
        String descriptionValue = "";
        String studyRegionId = "";
       
        try
        {
         
          List<FileItem> items = upload.parseRequest(req);
          logger.debug("items=" + items);
         
          for(FileItem item : items)
          {
            logger.debug("item=" + item);
View Full Code Here

    factory.setSizeThreshold(10*1024);
//    factory.setRepository(yourTempDirectory);

   
    // Create a new file upload handler
    ServletFileUpload upload = new ServletFileUpload(factory);

    upload.setFileSizeMax(MAX_FILE_SIZE);
   
   
    // Parse the request
    List<?> /* FileItem */ items;
    try {
      items = upload.parseRequest(request);
    }
    catch (FileUploadException e) {
      e.printStackTrace();
      response.sendError(HttpServletResponse.SC_EXPECTATION_FAILED, e.getMessage());
      return;
View Full Code Here

      throw new IllegalStateException(
        "ServletRequest does not contain multipart content. One possible solution is to explicitly call Form.setMultipart(true), Wicket tries its best to auto-detect multipart forms but there are certain situation where it cannot.");
    }

    // Configure the factory here, if desired.
    ServletFileUpload fileUpload = new ServletFileUpload(factory);

    // The encoding that will be used to decode the string parameters
    // It should NOT be null at this point, but it may be
    // especially if the older Servlet API 2.2 is used
    String encoding = request.getCharacterEncoding();

    // The encoding can also be null when using multipart/form-data encoded forms.
    // In that case we use the [application-encoding] which we always demand using
    // the attribute 'accept-encoding' in wicket forms.
    if (encoding == null)
    {
      encoding = Application.get().getRequestCycleSettings().getResponseRequestEncoding();
    }

    // set encoding specifically when we found it
    if (encoding != null)
    {
      fileUpload.setHeaderEncoding(encoding);
    }

    fileUpload.setSizeMax(maxSize.bytes());

    final List<FileItem> items;

    if (wantUploadProgressUpdates())
    {
      ServletRequestContext ctx = new ServletRequestContext(request)
      {
        @Override
        public InputStream getInputStream() throws IOException
        {
          return new CountingInputStream(super.getInputStream());
        }
      };
      totalBytes = request.getContentLength();

      onUploadStarted(totalBytes);
      try
      {
        items = fileUpload.parseRequest(ctx);
      }
      finally
      {
        onUploadCompleted();
      }
    }
    else
    {
      items = fileUpload.parseRequest(request);
    }

    // Loop through items
    for (final FileItem item : items)
    {
View Full Code Here

    DiskFileItemFactory factory = new DiskFileItemFactory();

    //
    // Create a new file upload handler
    //
    ServletFileUpload upload = new ServletFileUpload(factory);

    //
    // maximum size before a FileUploadException will be thrown
    //
    upload.setSizeMax(1024 * 1024 * 1024);

    //
    // process upload request
    //
    @SuppressWarnings("unchecked")
    List<FileItem> fileItems = upload.parseRequest(request);

    _logger.debug(serverPath);

    //
    // Only save .wgt files and ignore any others in the POST
View Full Code Here

        boolean isMultipart = ServletFileUpload.isMultipartContent(request);
        if (isMultipart) {

            // Streaming API typically provide better performance for file uploads.
            // Create a new file upload handler
            ServletFileUpload upload = new ServletFileUpload();

            try {
                // Now we should have the componentsName and upload directory to setup remaining upload of file items
                String compName = htUpload.get(FileUploadUtil.COMPONENT_NAME);
                status.setName(compName);

                // Parse the request and return list of "FileItem" whle updating status
                FileItemIterator iter = upload.getItemIterator(request);

                status.setReadingComplete();

                while (iter.hasNext()) {
                    item = iter.next();
View Full Code Here

TOP

Related Classes of org.apache.commons.fileupload.servlet.ServletFileUpload

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.