下载图像并保存它的最佳途径是什么?下载图像并保存下载格式
我当前的代码是:
temp_file = Tempfile.new "filename", "#{RAILS_ROOT}/tmp/"
temp_file.puts open(path_to_picture, 'User-Agent' => 'Test').read
mimetype = `file -ib #{temp_file.path}`.gsub(/\n/,"")
但现在看来,该mimetyp也不行。
此致敬礼
下载图像并保存它的最佳途径是什么?下载图像并保存下载格式
我当前的代码是:
temp_file = Tempfile.new "filename", "#{RAILS_ROOT}/tmp/"
temp_file.puts open(path_to_picture, 'User-Agent' => 'Test').read
mimetype = `file -ib #{temp_file.path}`.gsub(/\n/,"")
但现在看来,该mimetyp也不行。
此致敬礼
我已经使用了宝石“rio”,它工作得很好!
您不应该使用puts,因为它在图片的末尾写入换行符。
看看Rails的send_file
方法。您也可以在The Rails Way上阅读File Downloads Done Right。
你的代码是....不存在 – NDM 2009-09-24 11:46:56
现在,它应该是 – brainfck 2009-09-24 11:51:11