Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

How to store image, audio, video & text files POSTed to JSP page?  RSS feed

 
symbian ravi
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dear All,

When IMAGE files are POSTed to JSP page, how can i store them in image format i.e. in binary format?

My JSP page is accepting binary stream and writing it to a file. As the data is an image, i need to read the input in binary format and store it in binary(as-is) format. How can i do this in Java? Input to the JSP page can be anything - audio, video, text or image files. And hence, need to store them in binary format.

My code works for text file and is not working for .jpg file - i am getting blurred image.

Any help would be greatly appreciated.

Thanks,
symbian_ravi
 
Ulf Dittmer
Rancher
Posts: 42970
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello "symbian ravi"-

Welcome to JavaRanch.

Handling a binary file upload in a JSP won't work (JSPs are meant for handling text data). It's also a much better design to handle this in a servlet. There are libraries that handle the server part of file upload, namely the COS package (on servlets.com) and HttpFileUpload (on jakarta.apache.org/commons). Have a look at those, and you will likely need to do very little yourself.
 
symbian ravi
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks, Dittmer.

The data from the HTTP client is POSTed as the BODY i.e. the entire body is having the binary data and they are not in multi-part format.

If i need to handle the binary data stuffed into the HTTP body on my own, how can i achieve that? I am still using JSP as they are nothing but servlets. Pls advise.

Thanks,
symbain_ravi
 
Ulf Dittmer
Rancher
Posts: 42970
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can use request.getInputStream() to get the requests body as a binary stream.
 
symbian ravi
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks, Dittmer.

Managed to resolve.

Regards,
symbian_ravi
 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!