File uploads

190 views
Skip to first unread message

Luis Perichon

unread,
Nov 4, 2012, 8:14:25 AM11/4/12
to typh...@googlegroups.com
Hi!!!!
Im having trouble using Typhoeus v0.5 with an api that recieves a file upload.
According to the Getting Started guide:

response
= Typhoeus::Request.post("http://localhost:3000/posts",
  :body => {
    :title => "test post", :content => "this is my test",
    :file => File.open("thesis.txt","r")
  }
)

I did basically the same, using the absolute path for the file. but If I check the logs on the service I see this:

Parameters: {"avatar"=>{"file"=>"401804_4158820532594_47659601_n.jpgimage/jpeg/home/luis/Workspace/Padma/Padma/public/persona/foto/1769562/401804_4158820532594_47659601_n.jpg"}}

Notice how the service recieves the "file" param with something that doesnt look right...

If I upload manually from the UI the upload works and the parameters are like this:

Parameters: {"avatar"=>{"file"=>#<ActionDispatch::Http::UploadedFile:0xd8c3ff4 @original_filename="401804_4158820532594_47659601_n.jpg", @content_type="image/jpeg", @headers="Content-Disposition: form-data; name=\"avatar[file]\"; filename=\"401804_4158820532594_47659601_n.jpg\"\r\nContent-Type: image/jpeg\r\n", @tempfile=#<File:/tmp/RackMultipart20121104-3689-kv3j14>>}}

Help!! :D

Hans Hasselberg

unread,
Nov 4, 2012, 8:35:03 AM11/4/12
to typh...@googlegroups.com
Hi Luis,

Can you show me, what exactly you are doing?
--
You received this message because you are subscribed to the Google Groups "Typhoeus" group.
To view this discussion on the web visit https://groups.google.com/d/msg/typhoeus/-/Vm-7perr-RwJ.
To post to this group, send email to typh...@googlegroups.com.
To unsubscribe from this group, send email to typhoeus+u...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/typhoeus?hl=en.

Luis Perichon

unread,
Nov 4, 2012, 8:47:47 AM11/4/12
to typh...@googlegroups.com
Hi Hans!!!
Yeah, sure...

response = Typhoeus::Request.post("localhost:3001/v0/contacts/123/avatar",
                                     :params => {:avatar => {:file => File.open(person.photo, "r")}},
                                     :ssl_verifypeer => true,
                                     :timeout => 5500)

person.photo returns the file url

Hans Hasselberg

unread,
Nov 4, 2012, 8:54:38 AM11/4/12
to typh...@googlegroups.com
Hi Luis,

one thing I noticed is you're using :params which becomes url params, try :body instead.
To view this discussion on the web visit https://groups.google.com/d/msg/typhoeus/-/wNgBVLD1FWEJ.

Luis Perichon

unread,
Nov 4, 2012, 8:59:50 AM11/4/12
to typh...@googlegroups.com
YESSS!!!! That was it!!! thank you very much Hans!!!!
Reply all
Reply to author
Forward
0 new messages