Class: Aws::S3::Presigner

Inherits:
Object
  • Object
show all
Defined in:
lib/aws-sdk-core/s3/presigner.rb

Overview

Allows you to create presigned URLs for S3 operations.

Example Use:

signer = Aws::S3::Presigner.new
url = signer.presigned_url(:get_object, bucket: "bucket", key: "key")

Defined Under Namespace

Classes: PresignHandler

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Presigner

Returns a new instance of Presigner.

Parameters:

  • options (Hash) (defaults to: {})

    a customizable set of options

Options Hash (options):

  • :client (Client)

    Optionally provide an existing S3 client



14
15
16
# File 'lib/aws-sdk-core/s3/presigner.rb', line 14

def initialize(options = {})
  @client = options[:client] || Aws::S3::Client.new
end

Instance Method Details

#presigned_url(method, params = {}) ⇒ Object

Parameters:

  • method (Symbol)

    Symbolized method name of the operation you want to presign.

  • params (Hash) (defaults to: {})

    a customizable set of options

Options Hash (params):

  • :expires_in (Integer) — default: 86400

    The number of seconds before the presigned URL expires. Must be less than 604800 seconds (one week).



23
24
25
26
27
28
29
30
# File 'lib/aws-sdk-core/s3/presigner.rb', line 23

def presigned_url(method, params = {})
  request = @client.build_request(method, params)
  request.handle(PresignHandler, step: :sign, priority: 99)
  expires_in = params.delete(:expires_in) || 86400
  validate_expires_in_header(expires_in)
  request.context[:presigned_expires_in] = expires_in
  request.send_request.data
end