Rails 3 & Paperclip - Can I store images both on S3 & locally?

橙三吉。 提交于 2019-12-13 06:12:14

问题


We have a situation where we would like to start hosting images on Amazon's S3 service, however we don't want to upload all of our existing images to S3, instead we want to serve these "legacy" images from where they are hosted at the moment & going forward upload all new images to S3 and obviously serve those from S3.

Does anyone know if this is possible using either PaperClip or CarrierWave?

Thanks!


回答1:


Here how you do this if you don't have a any version create a version called :s3_version(anything you like)

something like this

class YourUploader < CarrierWave::Base

storage :file

version :s3_version do 
  storage :fog
  ## As far as I know it would save the file with appending 's3_version_(your_file_name)

  def full_filename(for_file)
    super.gsub(/s3_version_/,"")
  end

  def filename
    self.to_s.gsub(/s3_version_/,'')
  end
end

I think this would do all you want storing the file both locally as well as on S3 .

WARNING :

    I haven't tested this with multiple version 

but I guess it can too be done with :from clause I believe

Something like this

   version :thumb do
        process resize_to_fill: [280, 280] 
     end

     version :s3_thumb, :from_version => :thumb do
        storage :s3
      end

haven't tested it though

Hope this help



来源:https://stackoverflow.com/questions/17871568/rails-3-paperclip-can-i-store-images-both-on-s3-locally

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!