FYI all, you can use the same RPC servlet to handle the file upload,
simply override "service" in the RPC servlet, then handle the file
upload as shown in the examples above. In the case where it's not
multipart, or there is no uploaded file, just call super to keep the
RPC framework happy.

You will also need to set your form's action with
formPanel.setAction( GWT.getModuleBaseURL() + "Servletname" ); use the
same servlet name that's in your module's or web.xml file.

  @Override
  protected void service( HttpServletRequest request,
    HttpServletResponse response ) throws ServletException,
IOException
  {
    boolean isMultipart = ServletFileUpload.isMultipartContent( new
ServletRequestContext(
      request ) );
    if ( isMultipart )
    {
      FileItem uploadItem = getFileItem( request );
      if ( uploadItem == null )
      {
        super.service( request, response );
        return;
      }

      response.setContentType( "text/plain" );
      byte[] fileContents = uploadItem.get();
      // verify the file here....
      String myFile = new String(fileContents);
      if (myFile.contains( "xxxx" ))
      {
        //do stuff with the data....
        response.getWriter().write( "OK" );
      }
      else
      {
        response.getWriter().write( "Invalid file");
      }
    }
    else
    {
      super.service( request, response );
    }
  }

  private FileItem getFileItem( HttpServletRequest request )
  {
    FileItemFactory factory = new DiskFileItemFactory();
    ServletFileUpload upload = new ServletFileUpload( factory );
    upload.setSizeMax( 10000000 );

    try
    {
      List<FileItem> items = upload.parseRequest( request );
      for ( FileItem item : items )
      {
        if ( !item.isFormField()
          && "upload".equals( item.getFieldName() ) )
        {
          return item;
        }
      }
    }
    catch ( FileUploadException e )
    {
      return null;
    }
    return null;
  }

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Google Web Toolkit" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/Google-Web-Toolkit?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to