16 February 2009

Using Apache Commons FileUpload

I'm currently working on a project that required me to upload some files from a JSP driven web application. A quick Google search brought me to Apache Commons FileUpload. It's a very useful library, that if used correctly makes you're life a lot easier.

Once adding the dependency to my Maven 2 pom.xml and looking at the user guide, I expected it to work straight away, but unfortunately it didn't and I was not really sure why. My piece of code seemed to halt when trying to execute the following method:

List items = upload.parseRequest(request);


My friend Google was unable to provide me with the correct answer (that's why I'm writing it down now), but after a while I figured out what the problem was. The problem was: me not reading the documentation. On that same user guide page it states:


FileUpload depends on Commons IO, so make sure you have the version mentioned on the dependencies page in your classpath before continuing.


So in the end it was just another dependency. Not sure why it did not throw an error though, but after adding it to my pom.xml it worked like a charm.