Rest-client posting multipart to rails 2

E

e deleflie

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:[email protected]/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
 
E

Einar Magnús Boson

Hi,

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:[email protected]/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


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

einarmagnus
 
E

e deleflie

Hi,

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 =3D {'myObject[name]' =3D> "some name",
'myObject[details]' =3D> "some extra
details and stuff here.",
:myObject[image] =3D>
File.new('/baa/baa/screen-capture-1.png')
}
response =3D RestClient.post
"http://me:[email protected]/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


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]" =3D>
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,764
Messages
2,569,566
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top