Class: Aws::S3::Presigner

Inherits:
Object
  • Object
show all
Defined in:
lib/aws-sdk-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")

Constant Summary collapse

ONE_WEEK =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

60 * 60 * 24 * 7
FIFTEEN_MINUTES =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

60 * 15

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



21
22
23
# File 'lib/aws-sdk-s3/presigner.rb', line 21

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: 900

    The number of seconds before the presigned URL expires. Defaults to 15 minutes. As signature version 4 has a maximum expiry time of one week for presigned URLs, attempts to set this value to greater than one week (604800) will raise an exception.

  • :secure (Boolean) — default: true

    When ‘false`, a HTTP URL is returned instead of the default HTTPS URL.

  • :virtual_host (Boolean) — default: false

    When ‘true`, the bucket name will be used as the hostname. This will cause the returned URL to be ’http’ and not ‘https’.

  • :use_accelerate_endpoint (Boolean) — default: false

    When ‘true`, Presigner will attempt to use accelerated endpoint

Raises:

  • (ArgumentError)

    Raises an ArgumentError if ‘:expires_in` exceeds one week.



47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/aws-sdk-s3/presigner.rb', line 47

def presigned_url(method, params = {})
  if params[:key].nil? or params[:key] == ''
    raise ArgumentError, ":key must not be blank"
  end
  virtual_host = !!params.delete(:virtual_host)
  scheme = http_scheme(params, virtual_host)

  req = @client.build_request(method, params)
  use_bucket_as_hostname(req) if virtual_host
  sign_but_dont_send(req, expires_in(params), scheme)
  req.send_request.data
end