简体   繁体   中英

upload paperclip attachment to s3 using fog gem for specificaly one model

I am using fog gem to upload my paperclip attachmets to S3. This is my config file. But it attaches every models attachments to S3. I am trying to implement it on just one model... I couldnt find much documentation of fog with paperclip.

config.paperclip_defaults = {
          :storage => :fog,
          :fog_credentials => {
            provider: "AWS",
            aws_access_key_id: "AWS_ACCESS_KEY_ID",
            aws_secret_access_key: "AWS_SECRET_ACCESS_KEY"
          },
          :fog_directory => "BUCKET_NAME"
      }

The best way to do this will be to define the storage facilities for each model (I think)

By defining the defaults in the environment file, you're going to define those settings for all models. You can use this code for each model:


#app/models/your_model.rb
:styles => { :medium => "x300", :thumb => "x100" },
        :default_url => "your_url",
        :storage => :s3,
        :bucket => '******',
        :s3_credentials => S3_CREDENTIALS

#config/initializers/s3.rb
S3_CREDENTIALS = { :access_key_id => ENV['S3_KEY'], :secret_access_key => ENV['S3_SECRET']}

I appreciate this is not DRY, but it should help resolve your issue. Just take the code from your environment files & put into your models

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM