class Awscr::S3::Presigner

Defined in:

awscr-s3/presigner.cr

Constant Summary

MAX_TTL = 86400

Constructors

Instance Method Summary

Constructor Detail

def self.new(aws_access_key : String, aws_secret_key : String, endpoint : URI, region : String) #

[View source]
def self.new(client : Client) #

[View source]

Instance Method Detail

def presigned_form(bucket : String, key : String | Nil = nil, aws_session_key : String | Nil = nil, expires : Int32 = MAX_TTL, acl : String | Nil = nil, content_type : String | Nil = nil, success_action_status : String | Nil = nil, signer : Symbol = :v4, conditions : Hash(String, String) = Hash(String, String).new) #

Create a new presigned S3 POST HTML form for browser uploads.

Example

form = presigner.presigned_form(
  bucket: "my-bucket",
  key: "file.txt",
  acl: "public-read",
  content_type: "text/plain",
  conditions: {"x-id" => "PutObject"}
)

[View source]
def presigned_form(bucket : String, key : String | Nil = nil, aws_session_key : String | Nil = nil, expires : Int32 = MAX_TTL, acl : String | Nil = nil, content_type : String | Nil = nil, success_action_status : String | Nil = nil, signer : Symbol = :v4, & : Awscr::S3::Presigned::Policy -> ) #

Create a new presigned S3 POST form with full control over the policy.

Example

form = presigner.presigned_form("my-bucket", "helloworld.png") do |form|
  form.expiration(Time.unix(Time.local.to_unix + 1000))
  form.condition("acl", "public-read")
  form.condition("Content-Type", "image/png")
  form.condition("success_action_status", "201")
  form.condition("x-id", "PutObject")
end

[View source]
def presigned_url(bucket : String, key : String, method : Symbol = :get, expires : Int32 = MAX_TTL, include_port : Bool = false, force_path_style : Bool = false, signer : Symbol = :v4, additional_options : Hash(String, String) = Hash(String, String).new) #

Create a presigned S3 URL with full control over query parameters.

Example

url = presigner.presigned_url(
  "my-bucket",
  "docs/manual.pdf",
  method: :get,
  additional_options: {
    "response-content-disposition" => "inline",
    "x-id"                         => "GetObject",
  }
)

[View source]
def presigned_url(bucket : String, key : String, method : Symbol = :get, expires : Int32 = MAX_TTL, include_port : Bool = false, force_path_style : Bool = false, signer : Symbol = :v4, **kwargs) #

Create a presigned S3 URL using query parameters for a specific method.

Example

url = presigner.presigned_url(
  "my-bucket",
  "image.jpg",
  response_content_disposition: "inline"
)

[View source]