• 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
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

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

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks, Dittmer.

Managed to resolve.

Regards,
symbian_ravi
 
Hang a left on main. Then read this tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic