1

我正在使用带有 Rails 4 应用程序和 Amazon S3 存储的 Paperclip。在我的开发机器上,该站点运行在

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

当我使用 Paperclip 将文件上传到 S3 时,S3 中的远程路径会继承我的本地文件夹结构。

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

为什么会这样?我如何剥离那部分?我尝试更改:path属性,但这似乎只影响路径的“应用程序”部分(例如之后/assets/uploads) 我的网站仍在开发中,所以我不关心必须保留链接。

我的配置是...

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

1 回答 1

0

:url当我使用应该使用参数的参数时,我遇到了完全相同的问题:path

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'

我通过将配置更改为此来修复它:

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'
于 2015-02-08T20:10:14.200 回答