SOAP::SOAPBase64 (byte array) to Image (JPG/GIF)

J

Jalopy Jalopy

Hello,

Attempting to convert and expand on an old Java project. It pulls from
a SOAP project created from a WSDL using wsdl2ruby. The portion I am
having troubles with involves converting a "byte array" of image data
(either JPEG or GIF) into a valid image file. The soap call says it
returns an object of SOAP::SOAPBase64, but the documentation from the
server says it is a compressed image file in a byte array format.

The following is the Java code, that I want to get Ruby to duplicate:

// --------- Begin Java Code ------------------
import java.io.InputStream;
import java.io.ByteArrayInputStream;
import java.awt.image.BufferedImage;
import javax.imageio.ImageIO;

byte[] pic_bytes = getImageFromServer();
ByteArrayInputStream bais = new ByteArrayInputStream(pic_bytes);
BufferedImage bi = ImageIO.read((InputStream) bais);
ImageIO.write(bi, "JPEG", file_name);
// --------- End Java Code -------------------

I can get "data" from the server, but when I attempt to save it to a
file, it saves as characters (like ABCDEF). The Ruby version of
"getImageFromServer()" returns an object of String. I have tried
String.pack() to encode and decode from Base64, as well as other
formats, and I have tried using the RMagick library to save the image,
but the image "header" is not correct for a JPEG or GIF. I know the
Java version works, so I would like to know what about a
ByteArrayInputStream or BufferedImage makes the data become an image
that I cannot get to work in Ruby?

Thanks,
Jay
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,534
Members
45,007
Latest member
obedient dusk

Latest Threads

Top