• 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Tim Cooke
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Knute Snortum
  • paul wheaton
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Ron McLeod
  • Piet Souris
  • Ganesh Patekar
Bartenders:
  • Tim Holloway
  • Carey Brown
  • salvin francis

Send Image to web service

 
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.
 
Rancher
Posts: 43011
76
 
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: 43011
76
  • 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: 43011
76
  • 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.
 
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 !
 
Creativity is allowing yourself to make mistakes; art is knowing which ones to keep. Keep this tiny ad:
Enterprise-grade Excel API for Java
https://products.aspose.com/cells/java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!