I have been reading all about this for the past few hours but I don't seem to be getting anywhere. I am wanting to upload an image from a clients computer to the web app via a HTML form and a Servlet handling the incoming image.
To keep things simple, this is the only thing I am doing on the form and I am using the package from Apache FileUpload.
Here is the HTML form
And here is one of many pieces of code I have tried and haven't worked.
The issue seems to be on the line "List items = upload.parseRequest(request);"
and it is throwing the following error....
Can anyone point me in the right direction here as I have read various tutorials, read the official documentation here, and I am still none the wiser about how I need to go about fixing this.
Yep, the "Def" is for "definition" - which is found in the class file. And any class like "org/apache/commons/..." can be found somewhere around http://commons.apache.org/. If you haven't checked out all the libraries available there - you should, there's excellent stuff to be found.
Thrown if the Java Virtual Machine or a ClassLoader instance tries to load in the definition of a class (as part of a normal method call or as part of creating a new instance using the new expression) and no definition of the class could be found.
The searched-for class definition existed when the currently executing class was compiled, but the definition can no longer be found.
Just one final question related to file uploads, what would you suggest is the best option to ensure filenames don't clash?
I was thinking about just appending a unique ID at the end of the file name so "test.jpg" would turn into "test-123456789.jpg" which would solve the issue (as I want all of the files in one directory, not in separate folders within folders).
Although my only concern there is how I would track unique IDs.
Had a good play around with the method you mentioned and it was catching the error when there was a duplicate filename, although it was still uploading the image - both when I tried the image upload script within the try/catch block and outside of it - so not sure what to do best there?
I have actually got around this issue by having a naming convention programatically to ensure filenames are always renamed, but it would be good to know where I was going wrong with the what I tried using #createTempFile