• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Send Image to web service

 
Alex Parvan
Ranch Hand
Posts: 115
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,

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

Thank you.
 
Ulf Dittmer
Rancher
Posts: 42968
73
 
Alex Parvan
Ranch Hand
Posts: 115
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Rancher
Posts: 42968
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 115
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Rancher
Posts: 42968
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2198
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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!
 
Alex Parvan
Ranch Hand
Posts: 115
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2198
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 115
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 !
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic