从S3下载Carrierwave上传
我想使用carrierwave下载上传到S3的图像。 图像位于卡型号上,作为上传器安装。 我看到了这个答案 ,但是无法让这个解决方案起作用。 我的代码是:
#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!
最后一行抛出:“…导致exception(未定义的方法`body’为nil:NilClass)……”
我的carrierwave配置如下:
#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)
我在Rails 5中尝试过从AWS S3下载文件。
def download image = card.image # validate existing image from AWS S3 if image.try(:file).exists? data = open(image.url) send_data data.read, type: data.content_type, x_sendfile: true end end
我希望能帮助大家。
- Rails Paperclip S3 – 缺少必需:桶选项
- 阻止资产在本地进行预编译,以进行heroku rails asset_sync s3应用程序的本地生产测试
- AWS的未定义方法`find’:: S3 :: Bucket:Class
- 建议在Ruby中为S3 Bucket生成预签名URL的方法
- 我们可以找到Paperclip下载完成的时间吗?
- PDF.js消息:文件来源与查看者不匹配(Amazon S3)
- Rails ArgumentError(缺少必需:bucket选项)修复不起作用?
- 从AWS S3读取CSV文件时获取“Errno :: ENOENT:没有此类文件或目录@ rb_sysopen”
- Rails 4,Carrierwave-aws,图像在本地上传到amazon s3但未投放到生产中(Openshift)