下载Carrierwave上传从S3

下载Carrierwave上传从S3

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

问题描述

我想下载一个用carrierwave上传到S3图像。该图像是显卡型号,安装为一个上传。我看到这个答案,但有麻烦的解决方案工作。我的code是:

 从S3 #download图像
上传= card.image #image是安装上传
uploader.retrieve_from_store!(File.basename(card.image.url))
uploader.cache_stored_file!
 

这是最后一行抛出:......(对于无未定义的方法`身体':NilClass)导致了异常。

我的carrierwave配置是这样的:

 #配置/初始化/ carrierwave.rb
CarrierWave.configure做|配置|
  config.storage =:雾
  config.cache_dir =#{Rails.root} / tmp目录/上传
  ...
结束
 

解决方案

感谢 apneadiving 。它是那么容易,因为:

 图像= MiniMagick ::图像::开(card.image.to_s)
image.write(somepath)
 

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!

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

My carrierwave config looks like:

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

Thanks apneadiving. It was as easy as:

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

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

08-24 17:46