我希望创建一个Rails控制器,可以从网络上下载一系列jpg文件,并将它们直接写入数据库作为二进制文件(我不是想做上传表单)。
你知道如何实现吗?
谢谢。
编辑: 这里是我已经使用attachment-fu gem编写的一些代码:
我收到了一个“undefined method 'content_type' for #"错误。
你知道如何实现吗?
谢谢。
编辑: 这里是我已经使用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
}
我收到了一个“undefined method 'content_type' for #"错误。
content_type
未定义,因为attachement_fu期望的是一个文件,而不是字节流。我已经更新了我的答案,并附上了一些代码。 - Jonathan Julian