Meaningless Drivel is fun!*
The moose likes Web Services and the fly likes Send Image to web service 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 "Send Image to web service" Watch "Send Image to web service" New topic
Author

Send Image to web service

Alex Parvan
Ranch Hand

Joined: Dec 10, 2009
Posts: 115
Hello,

Is it possible to send a java Image to a web service ? If yes, can someone guide me on how to ?

Thank you.


"Quoting yourself is stupid" - Me
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41124
    
  45
This should help: http://www.ibm.com/developerworks/xml/library/x-tippass.html


Ping & DNS - my free Android networking tools app
Alex Parvan
Ranch Hand

Joined: Dec 10, 2009
Posts: 115
Actually i'm not using files, i take a picture using my phone, and then i want to upload it to a web service. I just have an Image object.
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41124
    
  45
The technique explained in the article can work with any kind of binary data, whether it ever existed as an actual file or not. Ultimately it also depends on what the web service expects as input (or is the service under your control?).
Alex Parvan
Ranch Hand

Joined: Dec 10, 2009
Posts: 115
I control the web service. Isn't it possible to just pass the Image the same way i would pass a String or an int ?
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41124
    
  45
Sure, you could encode the bytes that make up the image using something like base-64 and transfer that as a string. That's a rather low-level and pedestrian way of doing things, though, not much in the spirit of letting the technology do the work for you.
Ivan Krizsan
Ranch Hand

Joined: Oct 04, 2006
Posts: 2198
    
    1
Hi!
Parvan Alexandru wrote:I control the web service. Isn't it possible to just pass the Image the same way i would pass a String or an int ?

It is. Take a look at section 10.3 in my document at: http://faq.javaranch.com/content/Exam-Objectives-5.pdf
Best wishes!


My free books and tutorials: http://www.slideshare.net/krizsan
Alex Parvan
Ranch Hand

Joined: Dec 10, 2009
Posts: 115
You first take an Image from a servlet and send it to the client (it changed to byte[]), and then from the client back to the web service (while remaining byte[]). In your example, the Image is a byte[] while in my client application, is just an Image, how do i turn it into byte[] so i can send it to the web service?
Ivan Krizsan
Ranch Hand

Joined: Oct 04, 2006
Posts: 2198
    
    1
Hi!
Parvan Alexandru wrote:is just an Image, how do i turn it into byte[] so i can send it to the web service?

Take a look at the class javax.imageio.ImageIO!
By the way, there are no servlets in my example - just a web service.
Best wishes!
Alex Parvan
Ranch Hand

Joined: Dec 10, 2009
Posts: 115
I'm using J2ME, ImageIO is not available there

After the new year i'll look into it more, but thanks for your help so far.

Happy new year !
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Send Image to web service
 
Similar Threads
sending attachments from server to client
Handling non numeric argument
Uploading a image file from SD card to web service
Java image and byte[] for J2ME and J2SE
passing image files stored in hard drive