Rails: How to to download a file from a http and save it into database

Posted by Chris on Stack Overflow See other posts from Stack Overflow or by Chris
Published on 2010-04-03T14:46:04Z Indexed on 2010/04/03 17:43 UTC
Read the original article Hit count: 179

Filed under:
|

Hi, i would like to create a Rails controller that download a serie of jpg files from the web and directly write them into database as binary (I am not trying to do an upload form)

Any clue on the way to do that ?

Thank you

Edit : Here is some code I already wrote using attachment-fu gem :

http = Net::HTTP.new('awebsite', 443)
http.use_ssl = true
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
http.start() { |http|
   req = Net::HTTP::Get.new("image.jpg")
   req.basic_auth login, password
   response = http.request(req)
   attachment = Attachment.new(:uploaded_data => response.body)
   attachement.save
}

And I get an "undefined method `content_type' for #" error

© Stack Overflow or respective owner

Related posts about ruby-on-rails

Related posts about ruby