Imageupload through REST Webservice

1 view
Skip to first unread message

sigma

unread,
May 5, 2008, 3:32:28 PM5/5/08
to Ruby on Rails: Talk
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

Thiago Jackiw

unread,
May 5, 2008, 7:32:39 PM5/5/08
to Ruby on Rails: Talk
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 Jackiw
http://www.railsfreaks.com

sigma

unread,
May 6, 2008, 3:25:18 AM5/6/08
to Ruby on Rails: Talk
You're my hero ;-) It works now...
I only had to change request.stdinput.read to request.raw_post

Thank you

Thiago Jackiw

unread,
May 6, 2008, 3:43:18 AM5/6/08
to Ruby on Rails: Talk
Hey no problem. Yeah you could also use request.raw_post, guess I
forgot to mention hehe.

--
Thiago Jackiw
http://www.railsfreaks.com

Thiago Jackiw

unread,
May 6, 2008, 3:45:25 AM5/6/08
to Ruby on Rails: Talk
Hey no problem. Yeah you could also use request.raw_post, guess I
forgot to mention it hehe

--
Thiago Jackiw
http://www.railsfreaks.com

On May 6, 12:25 am, sigma <christoph.thom...@gmail.com> wrote:

Thiago Jackiw

unread,
May 6, 2008, 4:11:51 AM5/6/08
to Ruby on Rails: Talk
Sorry for the double post, was having a connection problem.

On May 6, 12:45 am, Thiago Jackiw <tjac...@gmail.com> wrote:
> Hey no problem. Yeah you could also use request.raw_post, guess I
> forgot to mention it hehe
>
> --
> Thiago Jackiwhttp://www.railsfreaks.com
Reply all
Reply to author
Forward
0 new messages