file upload example

1,006 views
Skip to first unread message

Kai

unread,
Dec 23, 2009, 3:38:51 AM12/23/09
to HTTParty Gem
Hi,
can someone provide a file upload example?

def self.upload_photo()
path = File.join(RAILS_ROOT, 'test/fixtures/photos/p1.jpg')
file = File.open(path)
result = post('/photos', :body => {:format=>'json', :photo =>
{:data => file})
file.close
return result
end

this doesn't seem to work.


Thanks,
Kai

John Nunemaker

unread,
Dec 29, 2009, 6:53:40 PM12/29/09
to httpar...@googlegroups.com
Pretty sure httparty doesn't support files. 


--

You received this message because you are subscribed to the Google Groups "HTTParty Gem" group.
To post to this group, send email to httpar...@googlegroups.com.
To unsubscribe from this group, send email to httparty-gem...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/httparty-gem?hl=en.



pete

unread,
Dec 30, 2009, 2:57:03 AM12/30/09
to HTTParty Gem

Like Jon said, HTTParty doesn't support files. You'll have to read the
file as a string first. Try something like this:

def self.upload_photo()
path = File.join(RAILS_ROOT, 'test/fixtures/photos/p1.jpg')

file = File.read( path )


post('/photos', :body => {:format=>'json', :photo => {:data =>
file})

end

pete

Reply all
Reply to author
Forward
0 new messages