Imageupload through REST Webservice

Hi together

I need a REST webservices, through which I can upload pictures from
a .NET client Desktop-Tool.

Here the “upload”-code-snipped from the .NET client tool:


Dim imageBytes() As Byte
imageBytes = ImageHelper.Image2ByteArray(image, format)
responseBytes = client.UploadData(url, “POST”, imageBytes)

Now my question is: how can i access the uploaded picture in my
Controller? Because there is no form and no fieldname for the picture
I don’t know how to access it…

Can anybody help me?

Greets
sigma

In your controller you have to read the input sent using the stdinput
attribute. The example below I’m using CURL to send an image to my
uploads_controller to simulate your REST webservice:

Sending data via CURL

cat photo.jpg | curl -X POST -H 'Content-type: image/jpeg --data-
binary @- “http://localhost:5000/uploads/create

Reading the content and storing to a file

class UploadsController < ApplicationController
def create
File.open(“assets/photo.jpg”, “wb”) {|f| f <<
request.stdinput.read}
render :text => “image upload sent\n”
end
end


Thiago J.
http://www.railsfreaks.com

You’re my hero :wink: It works now…
I only had to change request.stdinput.read to request.raw_post

Thank you

Hey no problem. Yeah you could also use request.raw_post, guess I
forgot to mention hehe.


Thiago J.
http://www.railsfreaks.com

Sorry for the double post, was having a connection problem.

Hey no problem. Yeah you could also use request.raw_post, guess I
forgot to mention it hehe


Thiago J.
http://www.railsfreaks.com

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs