I am currently using Uploadify (Flash + Ajax) to the Servlet (Commons Upload with OWASP ESAPI overlay) with success, but I was wondering how I would go about building in HTML5 support, or rather HTML5 with Flash support.
I know how to get the HTML5 drag and drop working, but I can’t quite figure out the mechanics of a Java Servlet connection and/or backend.
It’s not different from when using a regular
<form enctype="multipart/form-data">. All you need to do is to get that HTML5/JS code to send amultipart/form-datarequest with the dropped file, exactly the same kind of request as it would have been sent with a regular<input type="file">field. I’ll assume that you just can’t figure out how to achieve exactly that with HTML5/JS.You can utilize the new HTML5
FileAPI, XHR2FormDataandXMLHttpRequestUploadAPIs for this.Here’s a kickoff example of how your
dropevent handler should look like:That’s it. This example assumes that the servlet is mapped on a URL pattern of
/uploadServlet. In this example, the file is then available in Apache Commons FileUpload the usual way as aFileIteminstance with a field name offile.For more advanced stuff like attaching event handlers for monitoring the progress and like, checkout the following blogs:
I’ve played somewhat around it with the following SSCCE:
and this
UploadServletutilizing the new Servlet 3.0HttpServletRequest#getPart()API:See also: