Java Servlet Backend for Plupload
I wanted to use a rich web upload client for a personal project, and in a search I found Plupload. I am so impressed with Plupload! You can configure a single upload widget, and it will automatically choose the best rich client technology supported by a client’s browser. Who decides which rich client technology is best? You do! Plupload will use your prioritized list from the following choices: Flash, Gears, HTML 5, Silverlight, BrowserPlus, and HTML 4. Did I mention Plupload is open source? It does not get any better than this, folks!
For my project, I created a Java Servlet to receive the multi-part MIME POST request from Plupload. My solution uses the streaming API from Apache Commons FileUpload. The nice thing about the streaming API is that your Servlet can receive files that are too large to fit into memory.
Here is a link to (a simplified version of) my implementation of a Java Servlet backend for Plupload. The ZIP file contains the source code for the Servlet and a JSP dump page that fulfills the same function as the dump.php PHP page that comes with the Plupload distribution. The Servlet I am sharing is at the demonstration level of quality; it is not the same implementation I would actually use for a real application. But it is a good demonstration of how to handle the POST from Plupload. Some of my thoughts on using the Servlet include:
- By default, the Servlet saves the uploaded files to the web application server’s temp directory.
- Change the package for the Servlet class. It is currently set to “shadhome”.
- Add an entry in your web.xml configuration for the servlet. The URL that you configure in your web.xml will be the same one you should configure for the page that is using Plupload.
- For my project I have limited use for implementing the JSON responses that Plupload can accept, so that part is not very well represented.
- Again, this is a demonstration level implementation. Logging, exception handling, etc. are not well represented.
One final thought: technically this demonstration Servlet would handle saving files from any multi-part MIME POST request (not just from Plupload).
Drop me a note if you end up using this Servlet, or if you have any comments / questions.
UPDATE ON 2011-04-19: Lars has shared his example of a JSP that can receive the HTTP POST request from Plupload.
In: Articles · Tagged with: browserplus, dump.php plupload, file management, file upload, flash, google gears, html5, Java, multiple, Plupload, plupload demo, plupload java, plupload java servlet, Servlet, silverlight, upload, upload files

Shad finds high-value intersections between business strategy and information technology. He currently resides in the Madison, WI area.
on October 31, 2010 at 9:34 pm
Permalink
Thanks!
I am from china .
I have got your note . you are really good .
加油!
on November 26, 2010 at 11:17 am
Permalink
I’m from Brazil and really thanks!
on December 1, 2010 at 12:24 am
Permalink
thinks
on February 7, 2011 at 2:58 am
Permalink
I have a problem with html4 .it doesn’t recognised that the upload is complete and give the uploader a do file bach with the content {“jsonrpc” : “2.0″, “result” : null, “id” : “id”}
can you help me ??
greeting from germany
on February 24, 2011 at 1:06 pm
Permalink
I’ll give the HTML4 uploader a try and see what kind of error it shows. It may also be helpful to post your issue to the Plupload forum.
on April 5, 2011 at 4:38 am
Permalink
I use a slightly modified version of your code to handle the general case in https://github.com/jakobadam/plupload/, while handling the specific case in my own code.
Cheers.
on April 19, 2011 at 12:08 pm
Permalink
Lars, I finally had a chance to check out your JSP implementation of handling an upload from Plupload. Thanks for sharing this! I am sure many people will find your example useful.
on June 3, 2011 at 4:33 am
Permalink
Hi,
Thanks for the example. I have implemented and tried this in on of my applications. This is working fine for small file sizes less than 1 mb. If we try to upload a file of size 5mb or 10 mb Uploading is successful. But in the uploads folder if we try tom open the file, it is saying corrupted file. Could you please provide me some solution for this.
Thanks,
Chandrasekhar Ganta
on June 7, 2011 at 12:16 pm
Permalink
One thought that comes to mind is to check if your application server is timing out the uploads. Most application servers (and web servers if you are using a combination) have a setting where the default request timeout can be ignored for URLs that are considered to be applications. You will want to make sure the request is allowed to take as long as necessary (within some practical limitation) in order to allow large uploads to complete. Your web server has a default request timeout so that clients on slow connections cannot overly consume server resources.
The only other thing I can think about is that you must be sure to include the stream flushing calls before finishing the upload (as the example shows). But you are probably doing this correctly if you are getting smaller uploads to work.
Best wishes!
on September 19, 2011 at 10:50 pm
Permalink
Thanks very much!