0
我試圖使用expiring_url在回形針(使用回形針的instructions)來訪問Amazon S3的對象,但我得到一個錯誤:回形針和AWS S3,expiring_url,未定義的方法`憑證的零:NilClass
undefined method `credentials' for nil:NilClass
aws-sdk-core (2.5.3) lib/aws-sdk-core/signers/v4.rb:44:in `initialize'
aws-sdk-core (2.5.3) lib/aws-sdk-core/s3/presigner.rb:98:in `new'
如果我只是使用@ object.attachment.url,但是@ object.attachment.expiring_url會給出錯誤,那麼事情就會發生變化。這是爲什麼發生?
development.rb:
config.paperclip_defaults = {
storage: :s3,
url: ":s3_alias_url",
path: "/:class/:attachment/:id_partition/:style/:filename",
s3_host_alias: "example.cloudfront.net/assets",
s3_credentials: {
bucket: ENV['S3_BUCKET_NAME'],
access_key_id: ENV['AWS_ACCESS_KEY_ID'],
secret_access_key: ENV['AWS_SECRET_ACCESS_KEY'],
s3_region: ENV['AWS_REGION']
},
s3_permissions: :private
}
模型:
has_attached_file :attachment
控制器:
def download
redirect_to @object.attachment.expiring_url(10)
end
視圖:
<%= link_to "attachment", download_object_path(@object) %>
任何想法?