0

I'm migrating my user-uploaded files to a S3 bucket. They were successfully migrated thanks to this question, or so I think, as they are all listed in my bucket's dashboard. Then I followed this, this and this guides to set up S3 integration. My Gemfile looks like this:

(...)
#Image upload
gem 'paperclip'
gem 'aws-s3' # gem 'aws-sdk' won't work either
(...)

config/initializers/paperclip.rb:

Paperclip::Attachment.default_options[:path] = "/:class/:attachment/:id_partition/:style/:filename"
Paperclip::Attachment.default_options[:s3_host_name] = "sa-east-1.amazonaws.com"
Paperclip::Attachment.default_options[:url] = ":s3_path_url"

config/environments/development.rb and config/environments/production.rb both end with this configuration:

config.paperclip_defaults = {
    :storage => :s3,
    :s3_credentials => {
      :bucket => "MY_BUCKET",
      :access_key_id => "MY_ACCESS_ID",
      :secret_access_key => "MY_SECRET"
    }
  }

But when I try to get my attachment URL, for example User.find(163).avatar.url, it yields:

":s3_path_url?1405653975"

Any thoughts?

Community
  • 1
  • 1
Arthur Alkmim
  • 237
  • 1
  • 2
  • 10

1 Answers1

0

Use User.find(163).avatar.url, and if you later specify styles, you can pass that in to the url method like this: User.find(163).avatar.url(:style)

EDIT:

I would suggest then that you remove the file initializers/paperclip.rb and include the path to the config .paperclip_defaults like this:

config.paperclip_defaults = {
  :storage => :s3,
  :path => ":class/:attachment/:id/:style/:filename.:extension",
  :s3_credentials => {
    :bucket => "MY_BUCKET",
    :access_key_id => "MY_ACCESS_ID",
    :secret_access_key => "MY_SECRET"
  }
}
apeniche
  • 659
  • 3
  • 8