Skip to Main Content

Java EE (Java Enterprise Edition) General Discussion

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

org.apache.commons.fileupload.MultipartStream doubt

800396Oct 11 2009 — edited Oct 13 2009
Hello folks,

I have come accross a requirement, on the project I am working on, to upload images and doc files to MySql database from an upload perfomed on a jsp page. The upload is made thru a multipart/form-data form and the file upload handling is made by a servlet with the use of org.apache.commons.fileupload.MultipartStream(had to use this as input types other than file are also being passed on the request). I am able to get all the input correctly and have them inserted on the database, but my doubt relies on the fact that I receibe all uploaded bytes into a String variable and get the bytes from it into a byte array as String.getBytes. That is where my first question goes, is that right? If the string contains the bytes of the file, convertint]g it to ByteArrays would still contain the bytes of the file? The after doing that, all data is successfully inserted on the database. When I want to retrieve it from a database, I am not able to get the image(file) correctly retrieved though. I hava a bean that receives the byte array and when trying to get that to the JSP page through the use of ${class.object} I get nothing. I know this is way to confusing but can anybody get their times in trying to light me out on this?

Here is how I am getting the request params on the servlet:
while(nextPart) {
		  String headers = multipartStream.readHeaders();
		  System.out.println("Headers: " + headers);
		  System.out.println("Item name: " + headers.substring(38));
		  String item = headers.substring(38);
		  ByteArrayOutputStream data = new ByteArrayOutputStream();
		  multipartStream.readBodyData(data);
		  String value = new String(data.toByteArray());
                  (...)
                  nextPart = multipartStream.readBoundary();
}
This is my bean:
public class PropertyPictures {
	private int pictureID;
	private String title;
	private byte[] image;
	private String description;
	private Property property;
        (setters and getters)
}
This is how I am retrieving the image on the Jsp page:
<td><img class="houseimage" src="data:image/jpg;base64,${pictures.image}" alt="${pictures.description}"/></td>
I hope some one can help me with this.

Thanks and regards,
TS
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Nov 10 2009
Added on Oct 11 2009
2 comments
432 views