AWS :: S3 :: S3Object.url_for - 如何使用新的AWS SDK宝石做到这一点? [英] AWS::S3::S3Object.url_for - How to do this with the new AWS SDK Gem?

查看:150
本文介绍了AWS :: S3 :: S3Object.url_for - 如何使用新的AWS SDK宝石做到这一点?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直用这个永远和回形针和AWS-S3已经:

I've been using this forever with paperclip and aws-s3:

  def authenticated_url(style = nil, expires_in = 90.minutes)
      AWS::S3::S3Object.url_for(attachment.path(style || attachment.default_style), attachment.bucket_name, :expires_in => expires_in, :use_ssl => true)
  end

新曲别针使用AWS-SDK的宝石,打破这个给错误:

The new paperclip uses the AWS-SDK gem, which breaks this giving the error:

undefined method `url_for' for AWS::S3:Class

任何人都知道如何让这个方法与新的AWS-SDK宝石工作?

Anyone know how to get this method to work with the new AWS-SDK gem?

感谢

推荐答案

要使用AWS-SDK的宝石,你应该使用生成URL的<一个href="http://docs.amazonwebservices.com/AWSRubySDK/latest/AWS/S3/S3Object.html#url_for-instance_method">AWS::S3Object#url_for方法。照片 您可以使用#s3_object回形针附件访问S3Object实例。下面的代码段应该解决您的问题。

To generate a url using the aws-sdk gem you should use the AWS::S3Object#url_for method.
You can access the S3Object instance from a paperclip attachment using #s3_object. The snippet below should resolve your issue.

def authenticated_url(style = nil, expires_in = 90.minutes)
  attachment.s3_object(style).url_for(:read, :secure => true, :expires => expires_in).to_s
end

这篇关于AWS :: S3 :: S3Object.url_for - 如何使用新的AWS SDK宝石做到这一点?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆