【问题标题】:Paperclip Amazon S3 setup with Heroku回形针 Amazon S3 设置与 Heroku
【发布时间】:2011-03-27 00:02:42
【问题描述】:

has_attached_file :image, :storage => :s3, :s3_credentials => "#{RAILS_ROOT}/config/s3.yml", :path => "/:style/:filename"

我不确定:path => "/:style/:filename" 是什么。

我还想包含此附加图像的样式,这就是 :path 吗? 我想要的风格是这样的::styles => { :medium => "275x275>", :thumb => "175x155>" }

基本上这里发生的事情是我在 heroku 上进行设置,我不得不使用 S3,这似乎很简单,只是不习惯这种附件约定的东西。

另外,我刚刚注册了一个 S3 帐户……但 heroku 却在说它是免费的。这有什么关系?

【问题讨论】:

    标签: ruby-on-rails ruby amazon-s3 heroku paperclip


    【解决方案1】:

    “路径”指定 S3 上存储文件的位置。因此,如果您将附件指定为:

     has_attached_file :image, 
        :styles => { :medium => "275x275>", :thumb => "175x155>" },
        :storage => :s3, :s3_credentials => "#{RAILS_ROOT}/config/amazon_s3.yml",
        :path => "user/:attachment/:style/:id.:extension"
    

    一个示例 URL 将是:

    http://s3.amazonaws.com/bucket/user/image/thumb/347853856.jpg

    最后,S3 不是免费的(Heroku 只是声明传输/上传不计入基于使用的计算中)。如果您需要更多信息,Heroku 的 documentation 非常好。

    【讨论】:

    • Kevin:Paperclip 是否仍要求您为上传的任何文件写入 Heroku 上的本地文件系统?例如,文件是否首先进入 Heroku dyno(尤其是处理过的图像),然后进入 S3?还是 Paperclip 可以直接进入 S3 绕过 Heroku?
    • @iWasRobbed Paperclip 将在您的 Rails 应用程序中运行,从而在 Heroku 上运行。在这种情况下,文件将首先通过 Heroku。
    【解决方案2】:

    请注意,在 Rails 3.1 及更高版本中,它应该是 Rails.root 而不是 RAILS_ROOT

    【讨论】:

      猜你喜欢
      • 2011-12-27
      • 2011-07-31
      • 2012-04-15
      • 1970-01-01
      • 2011-08-09
      • 1970-01-01
      • 2013-08-02
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多