Meaningless Drivel is fun!*
The moose likes Web Services and the fly likes passing image files stored in hard drive Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Web Services
Bookmark "passing image files stored in hard drive" Watch "passing image files stored in hard drive" New topic
Author

passing image files stored in hard drive

Ted Addis
Greenhorn

Joined: Nov 19, 2008
Posts: 11
I have image files stored in hard drive with their address stored as a field in database.

say for example, I would have CUSTOMER_ID would have "C:\IMAGE_CUSTOMERID.jpg" as its image address stored in as a varchar2 field and I want to send the actual image IMAGE_CUSTOMER_ID.jpg inside a web service.

How would you advice sending such files inside a web service. I read about sending it as binary, but can you post a sample example?

Thank you in advance,
Chintan Rajyaguru
Ranch Hand

Joined: Aug 19, 2001
Posts: 341
In general, sending files via web services is not recommended - specially the media files because of their potential size. Alternatives to sending the file via web service would be to make the file available via ftp or similar and send the filename/location via web service. Another option is to use JMS to send the file (but again, depending on the size this may or may not be a good idea but it definitely works better than web service).

In the past people also sent files via base64 encoding. This encoding essentially turns an image into text, which can be embedded inside a SOAP message. You can find plenty of code samples on Google to encode an image into text and decode it back to image. Again, this may make the soap message way too big and isn't a preferred method anymore.

If you must send the file via web service, preferred way is to use MTOM/XOP. Find more information here, https://jax-ws.dev.java.net/nonav/2.1/docs/mtom-swaref.html


ChintanRajyaguru.com
SOADevelopment.com - Coming soon!
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12761
    
    5
Look into SAAJ - the SOAP with Attachments API for Java. You might start here at the Glassfish project.

Bill
Peer Reynders
Bartender

Joined: Aug 19, 2005
Posts: 2922
    
    5
The problem with web service attachments is that lack of supported standards. While MTOM/XOP is currently the preferred standard it is only supported by the most recent SOAP web service stacks. Earlier clients will only support a variety of even less well supported standards like DIME (not well supported under Java) and SOAP with Attachments (SwA) (not supported under .NET).

Given that you want to expose standard images it makes sense that you expose them as resources:

.../customers/{customerId}/image
.../customers/12345678/image
.../customers/87654321/image

The second one streams the image for customer 12345678 while the third one streams the image for customer 87654321. These images can be displayed in a browser or easily received programmatically.

Frameworks like Jersey (JAX-RS; JSR-311) and Restlet are used to build resources like these.

The Jersey Sample Applications

The samples run on Glassfish - however you should be able to run Jersey on Tomcat. Restlet even has connectors to run on web servers like Grizzly or Apache MINA which perform better than servlet-based web servers (Benchmark shows Restlet scalability).
[ December 11, 2008: Message edited by: Peer Reynders ]
 
Consider Paul's rocket mass heater.
 
subject: passing image files stored in hard drive
 
Similar Threads
Retrieve Images from oracle
IBM HttpServer and websphere Appserver
Embedding icon image
what happen if i add jar file which is in hard drive
reading a "non-context" HTML file in JSP