I am able to upload image attachements using paperclip to my application. But I would like to send the image to another application via faraday connection. Other attributes are successfully sent but not the attachment image. I am not sure what I should do to achieve this.
Asked
Active
Viewed 613 times
2 Answers
1
You need to use an HTTP library that can create Multipart Post requests.
For example Typhoeus can do file uploads: https://github.com/typhoeus/typhoeus#handling-file-uploads.
There's also Net::HTTP Multipart Post: https://github.com/nicksieger/multipart-post
And finally: https://github.com/jwagener/httmultiparty
Read the READMEs to any of those gems, they all make it equally easy to do file uploads. I like Typhoeus because it can do parallel requests. The other two are a bit simpler but equally useful.
Learn more about what a multipart form post is:

Community
- 1
- 1

DiegoSalazar
- 13,361
- 2
- 38
- 55
-
Thanks for the useful answer @diego.greyrobot. Coud you also give me idea how to make a get request to the other application and then be able to get paperclip attachment. Thanks – underScorePassionFruit Apr 25 '15 at 09:05
0
If I have to stick with using faraday, here is how to achieve the posting of paperclip attachments.
Faraday.new(:url => url) do |faraday|
faraday.request :multipart
end
And put the attachement as such in where post request happens
params['avatar'] = Faraday::UploadIO.new(avatar.map.path, 'image/jpeg')

underScorePassionFruit
- 315
- 3
- 19