从S3下载Carrierwave上传 [英] Download a Carrierwave upload from S3

查看:133
本文介绍了从S3下载Carrierwave上传的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想下载使用carrierwave上传到S3的图像。该图像在卡片模型上,作为上传者安装。我看到此答案,但无法将该解决方案工作。我的代码是:

I'd like to download an image that was uploaded to S3 using carrierwave. The image is on the Card model, mounted as an uploader. I saw this answer, but had trouble getting that solution to work. My code is:

#download image from S3
uploader = card.image       #image is the mounted uploader
uploader.retrieve_from_store!(File.basename(card.image.url))
uploader.cache_stored_file!

最后一行抛出:...引起异常(未定义的方法body为nil: NilClass)...

that last line throws: "... caused an exception (undefined method `body' for nil:NilClass)..."

我的载波配置如下:

#config/initializers/carrierwave.rb
CarrierWave.configure do |config|
  config.storage = :fog
  config.cache_dir = "#{Rails.root}/tmp/upload"
  ...
end


推荐答案

感谢 apneadiving 。这很简单:

image = MiniMagick::Image::open(card.image.to_s)
image.write(somepath)

这篇关于从S3下载Carrierwave上传的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆