• 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

passing image files stored in hard drive

 
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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,
 
Ranch Hand
Posts: 341
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Author and all-around good cowpoke
Posts: 13078
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Look into SAAJ - the SOAP with Attachments API for Java. You might start here at the Glassfish project.

Bill
 
Bartender
Posts: 2968
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 ]
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic