亚马逊s3提供带有附加查询字符串的图像路径

时间:2016-02-23 11:14:12

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

我使用Paperclip将图像上传到Ruby on Rails中的Amazon S3。 它工作正常,图像保存&显示得很好 但网址是喜欢

http://MYBUCKET.s3.amazonaws.com/users/avatars/12/medium_Noor.jpg?1456223556 我想知道这个查询如何在路径中追加?1456223556 字符串 是否由于S3或我在Code

中完成的事情而发生

在Config / initializers / paperclip.rb

Paperclip::Attachment.default_options[:url] = ':s3_domain_url'
Paperclip::Attachment.default_options[:path] = '/:class/:attachment/:id/:style_:filename'
Paperclip::Attachment.default_options[:s3_host_name] = 's3.amazonaws.com'

在模型中

  has_attached_file :avatar, styles: { medium: "500x500>", small: "250x250#", thumb: "100x100>" },
                        default_url: "/images/:style/missing.png",
                        storage: :s3,
                    s3_credentials: "#{Rails.root}/config/aws.yml"

  validates_attachment_content_type :avatar, content_type: /\Aimage\/.*\Z/

和控制器

def create
    @user = User.create( user_params )
    if @user.save
            redirect_to users_path
        else
            render :new
        end
  end

  private
  def user_params
    params.require(:user).permit(:avatar)
  end

0 个答案:

没有答案