# Imageupload through REST Webservice

**URL:** <https://www.ruby-forum.com/t/imageupload-through-rest-webservice/136723>\
**Category:** Rails\
**Created:** [May 5, 2008, 9:51pm UTC](https://www.ruby-forum.com/t/imageupload-through-rest-webservice/136723 "2008-05-05T21:51:09Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![sigma](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/dec6dc/32.png) [@sigma](https://www.ruby-forum.com/u/sigma)\
**Post date:** [May 5, 2008, 9:51pm UTC](https://www.ruby-forum.com/t/imageupload-through-rest-webservice/136723/1 "2008-05-05T21:51:09Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![sigma](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/dec6dc/32.png) [@sigma](https://www.ruby-forum.com/u/sigma)\
**Post date:** [May 6, 2008, 1:33am UTC](https://www.ruby-forum.com/t/imageupload-through-rest-webservice/136723/2 "2008-05-06T01:33:38Z")

</div>

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](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](http://www.railsfreaks.com)

---

<div class="post-metadata">

**Author:** ![sigma](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/dec6dc/32.png) [@sigma](https://www.ruby-forum.com/u/sigma)\
**Post date:** [May 6, 2008, 9:26am UTC](https://www.ruby-forum.com/t/imageupload-through-rest-webservice/136723/3 "2008-05-06T09:26:18Z")

</div>

You’re my hero 😉 It works now…  
I only had to change request.stdinput.read to request.raw\_post

Thank you

---

<div class="post-metadata">

**Author:** ![sigma](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/dec6dc/32.png) [@sigma](https://www.ruby-forum.com/u/sigma)\
**Post date:** [May 6, 2008, 9:43am UTC](https://www.ruby-forum.com/t/imageupload-through-rest-webservice/136723/4 "2008-05-06T09:43:58Z")

</div>

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

–  
Thiago J.  
[http://www.railsfreaks.com](http://www.railsfreaks.com)

---

<div class="post-metadata">

**Author:** ![sigma](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/dec6dc/32.png) [@sigma](https://www.ruby-forum.com/u/sigma)\
**Post date:** [May 6, 2008, 10:12am UTC](https://www.ruby-forum.com/t/imageupload-through-rest-webservice/136723/5 "2008-05-06T10:12:14Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![sigma](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/dec6dc/32.png) [@sigma](https://www.ruby-forum.com/u/sigma)\
**Post date:** [May 6, 2008, 9:45am UTC](https://www.ruby-forum.com/t/imageupload-through-rest-webservice/136723/6 "2008-05-06T09:45:47Z")

</div>

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

–  
Thiago J.  
[http://www.railsfreaks.com](http://www.railsfreaks.com)
