Paperclip + AWS S3, Prefixing remote path with my local path

。_饼干妹妹 提交于 2019-12-14 02:32:43

问题


I'm using Paperclip with a Rails 4 app and Amazon S3 storage. On my development machine, the site is running at

/Users/Jeff/Sites/example.com/web

When I upload a file with Paperclip to S3, the remote path in S3 inherits my local folder structure.

http://s3.amazonaws.com/example_com_bucket/Users/Jeff/Sites/example.com/web/public/assets/uploads/my_class/8/medium/some_image.png?1383060287

Why is this happening? How do I strip that part out? I tried changing the :path property but that only seemed to affect the "application" part of the path (e.g. after /assets/uploads) My site is still in development, so I don't care about having to preserve links.

My config is...

  config.paperclip_defaults = {
    :storage => :s3,
    :path => '/:class/:attachment/:id_partition/:style/:filename',
    :s3_credentials => {
      :bucket => 'example_com_bucket',
      :access_key_id => '...',
      :secret_access_key => '...'
    }
  }

回答1:


I had this exact same issue when I was using the :url parameter where I should have been using the :path parameter:

has_attached_file :primary_photo,
                    :styles => ...,
                    :storage => :s3,
                    :s3_host_name => 's3-us-west-2.amazonaws.com',
                    :s3_credentials => 'config/s3.yml',
                    :url => '/product/:attachment/:id/:style/:filename'

I fixed it by changing my config to this:

has_attached_file :primary_photo,
                    :styles => ...,
                    :storage => :s3,
                    :s3_host_name => 's3-us-west-2.amazonaws.com',
                    :s3_credentials => 'config/s3.yml',
                    :path => '/product/:attachment/:id/:style/:filename'


来源:https://stackoverflow.com/questions/19662695/paperclip-aws-s3-prefixing-remote-path-with-my-local-path

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