简体   繁体   English

Rails 3和Paperclip-我可以在S3或本地存储图像吗?

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

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. 在某些情况下,我们想开始在Amazon的S3服务上托管映像,但是我们不想将所有现有映像上传到S3,而是希望从托管它们的位置提供这些“旧”映像。现在和将来,将所有新图像上传到S3,显然可以为S3提供这些图像。

Does anyone know if this is possible using either PaperClip or CarrierWave? 有谁知道使用PaperClip或CarrierWave是否可行?

Thanks! 谢谢!

Here how you do this if you don't have a any version create a version called :s3_version (anything you like) 如果您没有任何版本,请按以下步骤进行操作:创建一个名为:s3_version的版本(任何您喜欢的版本)

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 . 我认为这将完成您想要在本地以及在S3上存储file所有操作。

WARNING : 警告 :

    I haven't tested this with multiple version 

but I guess it can too be done with :from clause I believe 但我想也可以用:from子句来完成

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 希望这个帮助

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何将Paperclip保存的旧图像迁移到新样式并将其保存到s3(而不是在本地保存新文件)? (路轨) - How to migrate old images saved by Paperclip to new styles and save it to s3 (and not saving the new files locally) ? (Rails) 通过本地打开的回形针将AWS S3图像上载到Rails,但不在生产环境中打开(Heroku) - AWS S3 Images Uploaded to Rails via Paperclip Opening Locally, but not in Production (Heroku) Rails 4 +回形针+设计+ S3:图像未上传到S3? - Rails 4 + Paperclip + Devise + S3: Images not uploading to S3? S3回形针导轨无法显示图像 - S3 Paperclip rails Can not display image 载波将图像本地存储在Heroku的S3上 - Carrierwave store images locally not on s3 at heroku 使用Paperclip和Amazon S3的ROR应用程序-可以存储但无法检索图像 - ROR application using Paperclip and Amazon S3 - can store but not retrieve images Rails / Paperclip:如何显示具有authenticated_read权限的S3图像? - Rails / Paperclip: How do I display images from S3 that have authenticated_read permissions? Rails 3,paperclip + S3 - 如何存储实例并保护访问权限 - Rails 3, paperclip + S3 - Howto Store for an Instance and Protect Access 如何使用Paperclip裁剪临时图像并将其存储在Rails 3中的Amazon S3中 - How to crop a temp image with Paperclip and store it in Amazon S3 in Rails 3 使用s3和Rails应用上的回形针上传两个图像 - Uploading two images using s3 and paperclip on rails app
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM