Reputation: 325
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.
Upvotes: 0
Views: 717
Reputation: 325
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')
Upvotes: 0
Reputation: 13521
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:
Upvotes: 1