Error with open-uri on Heroku
I'm using the code below to open and upload a Facebook profile image to S3 using Paperclip. The code works fine on my localhost (Rails 3.1, ruby 1.9.2 p290) but it breaks on heroku (bamboo-mri-1.9.2)
facebook_image_url = access_token['user_info']['image'].gsub("square", "large")
url = URI.parse(facebook_image_url)
#Follow the redirect of Facebook profi开发者_StackOverflow中文版le picture url
res = Net::HTTP.start(url.host, url.port) { |http|
http.get(facebook_image_url)
}
signed_in_resource.avatar = open(res['location'])
signed_in_resource.save
signed_in_resource
Does anyone have any suggestion?
I have hade similar problems solved the issue by using an updated version of URLTempfile. Also using S3 as image storage.
https://github.com/chris/paperclip_url_support, put in lib folder of your installation.
product = Product.first(:conditions => {:_id => self.product_id})
raise "Unable to get product with id #{self.product_id}" unless product
product.picture = URLTempfile.new(self.image_url)
product.save!
Using this in production on heroku with same config as you. (Heroku 1.9.3, Rails 3.1).
Hope this helps you.
精彩评论