GWT/GXT – File Upload

Share

If you are looking for a straightforward file upload solution in your Google Web Toolkit/Ext GWT based project, this article might help you. The problem with uploading files in such an application is that we can’t use the GWT RPC infrastructure for this. On the server side, the RemoteServiceServlet expects the request to be a RPC request, and therefore won’t work if we try to upload a file. The remaining possibility would be to use plain Servlet technology, including the apache Commons FileUpload utility. Also, after a short web search, I found the GWTUpload library, which, based on the Commons FileUpload package, makes it easy to add file upload capability to a GWT application. It also provides great features like showing a progress bar, server response with real information about the process, etc. Here is a complete example of how to use it in a GWT/GXT project:

File Upload using GWTUpload library, GWT and GXT

Download latest version of the library: gwtupload-0.6.3-compat.jar and include it in your classpath. Also, add these libraries to your application: commons-fileupload-1.2.2.jar, commons-io-2.0.1.jar and log4j-1.2.16.jar

Adjust the module file:

Client Side
Entry point class:

File Uploader widget:

Server Side
Customized servlet (extending ActionUpload and overriding executeAction):

log4j.properties

Finally, edit your web.xml and include the customized servlet:

Finally, there’s another very important peculiarity of what does Cialis that brings it so high above its alternatives. It is the only med that is available in two versions – one intended for use on as-needed basis and one intended for daily use. As you might know, Viagra and Levitra only come in the latter of these two forms and should be consumed shortly before expected sexual activity to ensure best effect. Daily Cialis, in its turn, contains low doses of Tadalafil, which allows to build its concentration up in your system gradually over time and maintain it on acceptable levels, which, consequently, makes it possible for you to enjoy sex at any moment without having to time it.

5 Comments
  • edw says:

    exactly what i need, thanks for sharing.
    Greetings from Indonesia.
    :)

    March 19, 2011 at 8:22 pm
  • Gavin says:

    Hi,

    I tried your code but got an exception launched when trying to upload a file. I added gwtupload-0.6.3-compat.jar to my buildpath and copied commons-fileupload-1.2.2.jar, commons-io-2.0.1.jar and log4j-1.2.16.jar to the libraries (war/WEB-INF/lib).

    On clicking the button send, I got this error :

    [WARN] Error for /suImage.fileUpload
    java.lang.NoClassDefFoundError: java.rmi.server.UID is a restricted class. Please see the Google App Engine developer’s guide for more details.
    at com.google.appengine.tools.development.agent.runtime.Runtime.reject(Runtime.java:51)
    at org.apache.commons.fileupload.disk.DiskFileItem.(DiskFileItem.java:109)
    at org.apache.commons.fileupload.disk.DiskFileItemFactory.createItem(DiskFileItemFactory.java:199)
    at org.apache.commons.fileupload.FileUploadBase.parseRequest(FileUploadBase.java:361)
    at org.apache.commons.fileupload.servlet.ServletFileUpload.parseRequest(ServletFileUpload.java:126)
    at gwtupload.server.UploadServlet.parsePostRequest(UploadServlet.java:796)
    at gwtupload.server.UploadAction.doPost(UploadAction.java:159)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:637)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
    at org.mortbay.jetty.servlet.ServletHolder.handle(ServletHolder.java:511)
    at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1166)
    at com.google.appengine.api.blobstore.dev.ServeBlobFilter.doFilter(ServeBlobFilter.java:58)
    at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157)
    at com.google.apphosting.utils.servlet.TransactionCleanupFilter.doFilter(TransactionCleanupFilter.java:43)
    at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157)
    at com.google.appengine.tools.development.StaticFileFilter.doFilter(StaticFileFilter.java:122)
    at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157)
    at org.mortbay.jetty.servlet.ServletHandler.handle(ServletHandler.java:388)
    at org.mortbay.jetty.security.SecurityHandler.handle(SecurityHandler.java:216)
    at org.mortbay.jetty.servlet.SessionHandler.handle(SessionHandler.java:182)
    at org.mortbay.jetty.handler.ContextHandler.handle(ContextHandler.java:765)
    at org.mortbay.jetty.webapp.WebAppContext.handle(WebAppContext.java:418)
    at com.google.apphosting.utils.jetty.DevAppEngineWebAppContext.handle(DevAppEngineWebAppContext.java:70)
    at org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java:152)
    at com.google.appengine.tools.development.JettyContainerService$ApiProxyHandler.handle(JettyContainerService.java:351)
    at org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java:152)
    at org.mortbay.jetty.Server.handle(Server.java:326)
    at org.mortbay.jetty.HttpConnection.handleRequest(HttpConnection.java:542)
    at org.mortbay.jetty.HttpConnection$RequestHandler.content(HttpConnection.java:938)
    at org.mortbay.jetty.HttpParser.parseNext(HttpParser.java:755)
    at org.mortbay.jetty.HttpParser.parseAvailable(HttpParser.java:218)
    at org.mortbay.jetty.HttpConnection.handle(HttpConnection.java:404)
    at org.mortbay.io.nio.SelectChannelEndPoint.run(SelectChannelEndPoint.java:409)
    at org.mortbay.thread.QueuedThreadPool$PoolThread.run(QueuedThreadPool.java:582)

    I couldn’t find any answer to this problem, can you ?

    Thanks!

    Gavin

    April 8, 2011 at 12:16 pm
  • Nebojsha says:

    Thanks a lot. Works like a charm. Greetings from Macedonia ;)

    May 7, 2011 at 1:58 pm
  • masfworld says:

    The problem is that gwtupload don’t work very fine with app engine. I work with gwtupload well in localhost but crash in appengine.

    Any idea???

    June 21, 2011 at 5:36 pm
  • I wanted to thank you for this fantastic read!! I definitely loved every little bit of it.

    I’ve got you book marked to check out new things you post…

    October 9, 2012 at 10:07 pm

Comments are closed.

By continuing to use the site, you agree to the use of cookies. More information

The cookie settings on this website are set to "allow cookies" to give you the best browsing experience possible. If you continue to use this website without changing your cookie settings or you click "Accept" below then you are consenting to this.

Close