【问题标题】:Paperclip + AWS S3, Prefixing remote path with my local pathPaperclip + AWS S3,用我的本地路径前缀远程路径
【发布时间】:2023-03-17 10:52:01
【问题描述】:

我正在使用带有 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 => '...'
    }
  }

【问题讨论】:

标签: ruby-on-rails amazon-web-services amazon-s3 ruby-on-rails-4 paperclip


【解决方案1】:

我在使用 :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'

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-05-27
    • 1970-01-01
    • 1970-01-01
    • 2013-07-04
    • 2015-03-06
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多