【问题标题】:Paperclip and Amazon S3 URL is too long回形针和 Amazon S3 URL 太长
【发布时间】:2010-08-13 18:35:26
【问题描述】:

当使用 Paperclip 将图像存储到 Amazon S3 时,图像的 url 太长:

例如http://s3.amazonaws.com/railsapp/Users/am/Desktop/railsapp/public/system/avatars/1/thumb/16110022.jpg?1171724004 (这在 mac 上基本上是 http://s3.amazonaws.com/[bucketname]/[path 到图像])

这是在我的用户模型中:

  has_attached_file :avatar, 
                :styles => { :thumb => "100x100>", :medium =>"250x250>" },
                :default_style => :thumb,
                :default_url => "/images/:attachment/missing_:style.png",
                :storage => :s3,                    
                :s3_credentials => "#{RAILS_ROOT}/config/amazon_s3.yml"

如何使 url 更短,使其不包含文件的长链接? 同时,有没有办法防止原始文件(不是调整大小的)形式被保存?

【问题讨论】:

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


    【解决方案1】:

    您是否尝试过定义:path 选项,例如:path => "avatars/:id/:style/:filename"

    【讨论】:

    • 您好,:path 和 :url 有什么区别?
    • 刚试过 - :path => "/avatars/:id/:style/:basename.:extension" - 效果很好 - 谢谢。我仍然对 url 的用途感到困惑
    • 我不知道url 对保存文件有什么影响,我认为它只是在检索过程中使用的东西。我也从来没有设置过url,只是path
    • "path" 是文件在文件系统上的保存位置。 “url”是指向该文件的外部链接。您的路径可能是 /usr/local/images/20.jpg 并且您的 URL 可能是:amazons3.com/assets/20.jpg
    猜你喜欢
    • 1970-01-01
    • 2011-03-27
    • 2011-12-27
    • 2012-12-03
    • 1970-01-01
    • 2011-11-07
    • 1970-01-01
    • 2012-04-15
    • 2011-01-02
    相关资源
    最近更新 更多