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

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

问题描述

我一直在用回形针和 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 gem,这会导致错误:

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

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

有人知道如何让这种方法与新的 AWS-SDK gem 配合使用吗?

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

推荐答案

要使用 aws-sdk gem 生成 url,您应该使用 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 Gem 做到这一点?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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