# Rest-client posting multipart to rails 2

**URL:** <https://www.ruby-forum.com/t/rest-client-posting-multipart-to-rails-2/154365>\
**Category:** Ruby\
**Created:** [November 28, 2008, 10:19am UTC](https://www.ruby-forum.com/t/rest-client-posting-multipart-to-rails-2/154365 "2008-11-28T10:19:51Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![e\_deleflie](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/858c86/32.png) [@e\_deleflie](https://www.ruby-forum.com/u/e_deleflie)\
**Post date:** [November 28, 2008, 10:19am UTC](https://www.ruby-forum.com/t/rest-client-posting-multipart-to-rails-2/154365/1 "2008-11-28T10:19:51Z")

</div>

Hi all,

I’m using rest-client (in a Shoooes app) to post a multi-part form to  
my rails server. I’ve been struck down by a gotcha (which may not be a  
gotcha for non-newbies).

What I want to do is post an image file within the form. Examples show  
that the correct syntax is such:

```
          params = {'myObject[name]' => "some name",
                              'myObject[details]' => "some extra

```

details and stuff here.",  
:myObject[image] =\>  
File.new(‘/baa/baa/screen-capture-1.png’)  
}  
response = RestClient.post  
“[http://me:removed\_email\_address@domain.invalid/myObject.xml](http://me:removed_email_address@domain.invalid/myObject.xml)”, params

but :myObject[image] is not a valid symbol … and that’s how rails  
creates the names of the fields in the forms …

Any ideas?

Etienne

---

<div class="post-metadata">

**Author:** ![e\_deleflie](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/858c86/32.png) [@e\_deleflie](https://www.ruby-forum.com/u/e_deleflie)\
**Post date:** [November 28, 2008, 10:32am UTC](https://www.ruby-forum.com/t/rest-client-posting-multipart-to-rails-2/154365/2 "2008-11-28T10:32:09Z")

</div>

Hi,

On 28.11.2008, at 09:14 , e deleflie wrote:

> ```
> 'myObject[details]' => "some extra
> 
> ```
> 
> Any ideas?
> 
> Etienne

Your two first parameters have strings as keys, not symbols.

einarmagnus

---

<div class="post-metadata">

**Author:** ![e\_deleflie](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/858c86/32.png) [@e\_deleflie](https://www.ruby-forum.com/u/e_deleflie)\
**Post date:** [November 28, 2008, 10:40am UTC](https://www.ruby-forum.com/t/rest-client-posting-multipart-to-rails-2/154365/3 "2008-11-28T10:40:25Z")

</div>

On Fri, Nov 28, 2008 at 8:26 PM, Einar Magnús Boson  
[removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> > What I want to do is post an image file within the form. Examples show
> 
> Your two first parameters have strings as keys, not symbols.  
> yeah, but that seems to work fine …

I worked out I can do :“myObject[image]” =\>  
File.new(‘/baa/baa/screen-capture-1.png’) but that still doesn’t …  
it creates the below message in Rails:

UploadColumn::UploadNotMultipartError (Do not know how to handle a  
string with value ‘(File /baa/baa/screen-capture-1.png)’ that was  
uploaded. Check if the form’s encoding has been set to  
‘multipart/form-data’.):

Etienne

---

<div class="post-metadata">

**Author:** ![e\_deleflie](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/858c86/32.png) [@e\_deleflie](https://www.ruby-forum.com/u/e_deleflie)\
**Post date:** [November 28, 2008, 1:30pm UTC](https://www.ruby-forum.com/t/rest-client-posting-multipart-to-rails-2/154365/4 "2008-11-28T13:30:17Z")

</div>

On Fri, Nov 28, 2008 at 4:34 AM, e deleflie [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> > > gotcha for non-newbies).  
> > > response = RestClient.post
> 
> string with value ‘(File /baa/baa/screen-capture-1.png)’ that was  
> uploaded. Check if the form’s encoding has been set to  
> ‘multipart/form-data’.):

Perhaps you want to stick the contents of that file in the  
“myObject[image]” param? If so File.new is not going to do it.

Try File.read(‘/baa/baa/screen-capture-1.png’)

HTH,  
Michael G.
