- Ajax Upload; A file upload script with progress-bar, drag-and-drop - This is my pick. Disclaimer: I contributed the servlet code to handle the requests. Here is a link to the source: File Uploader (GitHub).
- AJAX Multiple File Upload Form Using jQuery - Based on Andrew Valums original work.
- Google App Engine and File Upload - Google App Engine method.
- Safari 4 Multiple Upload With Progress Bar - Limited by by browser type.
- Upload multiple files with a single file element - a different approach. Very simple to implement.
jQuery Multiple File Upload Plugin - This worked but was very flaky for me. The first item works better. - FancyUpload - Swiff meets Ajax (v3.0) - I did not experiment with this one. I as told about it, but I had already decided on working with Andrew Valums on his elegant solution.
Friday, December 24, 2010
Multiple File Upload Options
I was recently confronted with a question about how to do multiple file
uploads from a browser based application. The HTML 4.x specification is
pretty open on the file upload requirements, and all of the browser
implementations are very basic. Firefox, Safari, Web Toolkit, and
Internet Explorer all provide a method to upload one file at a time, but
no multiple file upload. As a result, clever coders have come up with a
number of solutions. Here are a few.
Wednesday, December 08, 2010
Apache HTTPClient 4.x Preemptive Authentication
I am using the Apache HttpClient for some work I am doing at the office.
It is a really cool utility to perform web based work. A common
requirement of such work is to use authentication.
The default behavior of the HttpClient is to try and connect to the resource and read the response. If the response is a 401 Unauthorized, the client sends the request again using the credentials that are set in the client. This results in an unnecessary double posting of the request. It is however compliant with RFC2616 Section 10.4.2 which describes this behavior.
In the previous version of the client (3.x), you could set the preemptive authentication with the code below:
However, version 4.x does not support this convenient arrangement. There is a more flexible arrangement using interceptors. The client supports interceptors on both the request, and the response. The use of interceptors makes the code a little more complex, but the flexibility of using multiple interceptors, and ordering them makes up for the additional code required.
I can not provide an example of my code since it was something I created for work, but here are two examples. The first is complete, and the second is simply an example.
There is an additional post on stackoverflow which indicates you may be able to use a simple addition to the header. This may work for simple clients, but it is not as flexible as the interceptor form. I have not tested the code, but have included Adam Batkin's code snippet below.
The default behavior of the HttpClient is to try and connect to the resource and read the response. If the response is a 401 Unauthorized, the client sends the request again using the credentials that are set in the client. This results in an unnecessary double posting of the request. It is however compliant with RFC2616 Section 10.4.2 which describes this behavior.
In the previous version of the client (3.x), you could set the preemptive authentication with the code below:
httpClient.getParams().setAuthenticationPreemptive(true);
However, version 4.x does not support this convenient arrangement. There is a more flexible arrangement using interceptors. The client supports interceptors on both the request, and the response. The use of interceptors makes the code a little more complex, but the flexibility of using multiple interceptors, and ordering them makes up for the additional code required.
I can not provide an example of my code since it was something I created for work, but here are two examples. The first is complete, and the second is simply an example.
There is an additional post on stackoverflow which indicates you may be able to use a simple addition to the header. This may work for simple clients, but it is not as flexible as the interceptor form. I have not tested the code, but have included Adam Batkin's code snippet below.
String username = ...
String password = ...
UsernamePasswordCredentials creds = new UsernamePasswordCredentials(username, password);
HttpRequest request = ...
request.addHeader(new BasicScheme().authenticate(creds, request));
Labels:
Apache
,
example
,
frameworks
,
Java
,
Web
Apache Commons IO 2.0
Congrats to the Apache Commons IO Team on the release of the 2.0 framework. It has been a long time coming. The latest libraries require Java 1.5 which is a quantum jump in Apache terms. The old library required Java 1.3.
The
Have you ever needed to create unit tests on methods which require a closed
There are some other nice classes especially for debugging like
If you have not taken the time to look at these great tools, take a couple of minutes to just look at the javadocs. I am sure you will be impressed like me.
The
IOUtils
class provides a number of convenience methods to handle most IO operations. One of my favorite methods is IOUtils.copy(InputStream input, OutputStream output)
. A simple method, but so very useful since it is so common.Have you ever needed to create unit tests on methods which require a closed
InputStream
, or OutputStream
. I am sure you have, if not you just have not gotten there yet. Apache Commons IO offers you ClosedInputStream
and ClosedOutputStream
.There are some other nice classes especially for debugging like
CountingInputStream
and CountingOutputStream
which records the number of bytes read, or written. I can see another use for cloud computing models where you are charged for data transfers. This can help you keep track of those numbers for comparison with your charges.If you have not taken the time to look at these great tools, take a couple of minutes to just look at the javadocs. I am sure you will be impressed like me.
Labels:
Apache
,
frameworks
,
Java
Subscribe to:
Posts
(
Atom
)
Popular Posts
-
Introduction This article is not another diatribe to tell you the importance of unit testing. I think we can all agree that it is important...
-
A friend of mine asked me if there was a list of reserved words in EL and JSF. He had previously looked for it, and after some Google search...
-
I saw a question posed on stackoverflow called Trouble with Primefaces 3.0.M2 SelectOneMenu Ajax behavior and I had just done an example a...
-
I was working on a couple of SSL based issues when I made a couple of observations. The default self-signed key generation in Java does not ...
-
This is an example on how to make a system call to the local operating system to execute external programs. This example was written to work...
-
We have been doing a lot of work lately with PrimeFaces. A common set of questions comes up about displaying <p:dialog/> boxes on a pa...
-
I was asked earlier today how to reset fields in a JSF application, if the validation fails. In his case, he had a Richfaces table which had...
-
Image by quasarkitten via Flickr The basics for creating a Maven archetype can be found in the Maven - Guide to Creating Archetypes . The ...
-
Previously, I posted an example of how to use JSF 1.2 with form based authentication (j_security_check). In this example, I use JSF 2.x to...
-
Abstract A common use case is to iterate over a collection of elements, and display them on a page. In the world of JSP, we would use a Ja...