Hello all
I was wondering if someone could help me with a multipart/ form data design issue.
Here's some background on my requirements.
I'm developing a new feature for an application where users are able to create employee profiles, which will consist of all of the employee's details as well as an employee image. A
servlet will receive the request; create the employee image on the filesystem, and save the employee details (with the path to the image) to the database. The image is not required but if it is it will need to be of specific type (ie., jpeg, gif), size, and dimensions.
I've considered using the orielly's Multipartparser and Multipartrequest class to do the job, and while they do perform a lot of what I need they don't meet all of my design needs. The reason being that all of the submitted information will have to be validated before proceding to create the image on the file system. So, I've decided to create my own parser.
I've printed out all of the "stuff" so I now I'm able to see that I'll have to parse the "Content-Disposition: form-data" to look for both request parameters and file parts, but I'm not sure what to do with the portion that represents a file. I need to perform validation on the file part: size, dimension, etc.
Here's the way I've set my "testing" method up:
BufferedReader br= request.getReader();
LineNumberReader lr = new LineNumberReader(br);
String lineNumber = null;
PrintWriter out = response.getWriter();
out.println("<table>");
while ((lineNumber = lr.readLine()) != null) {
out.println("<tr>");
out.println("<td>");
out.println(lineNumber);
out.println("</td>");
out.println("</tr>");
}
out.println("</table>");
Here's the output:
-----------------------------7d4155f1c02a4
Content-Disposition: form-data; name="upload"; filename="C:\surf.jpg"
Content-Type: image/pjpeg
�THIS WOULD REPRESENT THE FILE PART (not shown)�
-----------------------------7d4155f1c02a4
Content-Disposition: form-data; name="dummy"
test -----------------------------7d4155f1c02a4--
Is there a class that I can use to pump file data into that will give me an image representation where I can later call methods like getHieght(), getWidth()? Am I living in a fantasy world?
Thanks in advance for any insight you may be able to provide me.