Class: PresignedUpload::Adapter::Aws

Inherits:
Base
  • Object
show all
Defined in:
lib/presigned_upload/adapter/aws.rb

Overview

The ‘Aws` class is an adapter for interacting with the Amazon Simple Storage Service (S3) using the AWS SDK. It inherits from `Adapter::Base` and implements methods for generating presigned URLs, uploading files, and deleting files.

See Also:

Instance Method Summary collapse

Methods inherited from Base

#initialize

Constructor Details

This class inherits a constructor from PresignedUpload::Adapter::Base

Instance Method Details

#delete_file(key) ⇒ void

This method returns an undefined value.

Deletes the file with the specified key from the storage.

Parameters:

  • key (String)

    The key or identifier of the file to be deleted.



42
43
44
# File 'lib/presigned_upload/adapter/aws.rb', line 42

def delete_file(key)
  bucket.object(key).delete
end

#presigned_url(key, method, expires_in) ⇒ String

Generates a presigned URL for the specified key, HTTP method, and expiration time.

Parameters:

  • key (String)

    The key or identifier of the file in the storage.

  • method (Symbol)

    The HTTP method for which the presigned URL is generated (e.g., :put, :get).

  • expires_in (Integer)

    The duration in seconds for which the URL is valid.

Returns:

  • (String)

    The presigned URL for the specified key, method, and expiration time.



22
23
24
# File 'lib/presigned_upload/adapter/aws.rb', line 22

def presigned_url(key, method, expires_in)
  bucket.object(key).presigned_url(method, expires_in: expires_in)
end

#upload_file(file, key) ⇒ void

This method returns an undefined value.

Uploads the specified file to the storage with the given key.

Parameters:

  • file (String)

    The path to the local file to be uploaded.

  • key (String)

    The key or identifier for the file in the storage.



32
33
34
35
# File 'lib/presigned_upload/adapter/aws.rb', line 32

def upload_file(file, key)
  object = bucket.object(key)
  object.upload_file(file)
end