• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Multipart parsing...Help!!!!!

 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Ranch Hand
Posts: 60
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

I suppose u r using file upload facility to send the image file.
I think u can try javax.mail.internet.MimeMultiPart through which you can get the InputStream of the Image at the server.After you get the Input Stream you can use the Java Advanced Imaging package

Java Advanced Imaging

--------
A T U L
 
Raul Vieira
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Atul I'll have a look.
 
Ranch Hand
Posts: 245
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'd encourage you to move this to a struts environment. In this way you can use an ActionForm on the server side to receive the file. Your ActionForm will override the validate() method and do the appropriate validation. On the JSP side you can use the <html:file> tag to manage your upload.

I do recognize that if you don't already have a struts environment that this is not the best solution.
 
Anything worth doing well is worth doing poorly first. Just look at this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic