开发者

Granular 'public' settings on uploaded files with Fog and Carrierwave

开发者 https://www.devze.com 2023-03-21 16:14 出处:网络
I am creati开发者_运维技巧ng a rails app that lets an administrator upload photos that are optionally publicly displayed.For the upload / storage process I am using the Carrierwave gem along with the

I am creati开发者_运维技巧ng a rails app that lets an administrator upload photos that are optionally publicly displayed. For the upload / storage process I am using the Carrierwave gem along with the Fog gem and S3. The issue is that in order to get this all working, I have to make every file uploaded to the s3 bucket public. Is there a way to make files public / private on a file-by-file basis? Also, if this file-by-file granularity is possible, can it extend down to versions of images (created by automatic Carrierwave resizing)?

Currently, I have the following line in my carrierwave initializer:

  config.fog_public = true


Actually, it's dead simple in Carrierwave.

You can do this:

class PrivateUploader < StandardUploader  

  @fog_public = false

Or (untested but should work perfectly) this:

class PrivateUploader < StandardUploader  


  def fog_public
    if local_condition
      true
    else
      false
    end
  end

:-)

I haven't tried DragonFly, but now that a couple of issues have been fixed in the last 2 months with Carrierwave, it's far superior to anything else I've seen. Insanely flexible.

//matt


Just have to make your uploader class override the base class. I tore my hair out today too.. :( This worked for me:

Using Carrierwave 0.8.0 (in May 2013) /app/uploaders/whatever_uploader.rb

class WhateverUploader < CarrierWave::Uploader::Base
  def fog_public
    true # or false
  end
end
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号