Download Carrierwave Download from S3

I would like to upload an image that was uploaded to S3 using carrierwave. The image is on the map model installed as a bootloader. I saw this answer , but could not get this 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 the last line throws: "... threw an exception (undefined` body 'method for nil: NilClass) ...

My carrier configuration is as follows:

 #config/initializers/carrierwave.rb CarrierWave.configure do |config| config.storage = :fog config.cache_dir = "#{Rails.root}/tmp/upload" ... end 
+4
ruby ruby-on-rails amazon-s3 download carrierwave
source share
2 answers

Thanks apneadiving . It was as simple as:

 image = MiniMagick::Image::open(card.image.to_s) image.write(somepath) 
+2
source share

I tried this in Rails 5 to download a file from 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 

I hope to help everyone.

0
source share

All Articles