Sending/Receiving Image Data over REST

Hi,

I’ve got a REST API that accepts PUT/POST requests of image data.
(Well, that’s the plan.)

Here are the relevant lines:

My client (using ImageMagick) application reads image data from a file
and then coverts it’s data into a blob:

image = Magick::Image::read(@custom_image.full_filename).first

Obj.image_data = image.to_blob
Obj.save

The ‘Obj.save’ initiates a REST request (PUT/POST)that contains the
binary image data as a member of params

My controller on the REST app can do this:

data = params[:image_data] #=> data is now a String

Here’s how I’m saving the image data to the file system:

File.open(path, “wb”) do |f|
f.binmode
f.write data
f.close
end

And data is saved…but the image is unreadable, (ImageMagick on the
REST app doesn’t recognize the image as a properly formatted jpeg.

My questions are these:

  1. What is the best way to send/receive image data to a REST service?
  2. Is there anything terribly wrong with the approach I’ve taken?

Thanks for your help,
EB

I’m curious about this too, did you find any answers to your
question? Or do you just have to generate the image, save it
somewhere and send the URL back in the REST API request instead of the
blob?

On Apr 24, 5:09 pm, Elliott B. [email protected]

Marston A. wrote:

I’m curious about this too, did you find any answers to your
question? Or do you just have to generate the image, save it
somewhere and send the URL back in the REST API request instead of the
blob?

On Apr 24, 5:09 pm, Elliott B. [email protected]

Yes, I found a solution. I Base64 encoded the image data on the sending
side and then Base64 unencoded on the other receiving side.

Marston A. wrote:

Elliott,

Great, simple solution. How big are the images you’re sending over?
Do you notice any performance penalties? I’m thinking of doing the
same, though the images I have are fairly small ( < 75k).

On Jul 13, 2:19 pm, Elliott B. [email protected]

The performance is acceptable so far, but I’ve been working locally, so,
I don’t know how it behaves over the internet. -EB

Elliott,

Great, simple solution. How big are the images you’re sending over?
Do you notice any performance penalties? I’m thinking of doing the
same, though the images I have are fairly small ( < 75k).

On Jul 13, 2:19 pm, Elliott B. [email protected]