Belt v0.4.0 Belt.Provider.S3

Provider module offering support for S3-compatible storage services though ExAws.

All S3-compatible services that use the v4 signature are supported, e. g. Amazon S3, EMC Elastic Cloud Storage or Minio.

Usage

{:ok, config} = Belt.Provider.S3.new([…])
{:ok, %FileInfo{}} = Belt.store(config, "/path/to/file.ext")

Caveats

Unlike Belt.Provider.Filesystem and Belt.Provider.SFTP, Belt.Provider.S3 pre-calculates the hashes of a file before uploading it and stores them as metadata. This means that only hashes that were requested in the options for Belt.store/3 can be retrieved later. If a service does not support storing metadata, hashes can not be retrieved.

{:ok, file_info} = Belt.store(config, "/path/to/file.ext", hashes: [md5, sha])
Belt.get_info(config, file_info.identifier, hashes: [md5, sha, sha256])
#=> %{hashes: ["a1…ff", "d9…ca", :unavailable]}

Summary

Types

Options for creating an Filesystem provider

Functions

Creates a new S3 provider configuration with default credentials

Implementation of the Belt.Provider.delete/3 callback

Implementation of the Provider.delete_all/2 callback

Implementation of the Provider.delete_scope/3 callback

Implementation of the Belt.Provider.get_info/3 callback

Implementation of the Belt.Provider.get_url/3 callback

Implementation of the Belt.Provider.list_files/2 callback

Creates a new S3 provider configuration

Implementation of the Belt.Provider.store/3 callback

Implementation of the Belt.Provider.store_data/3 callback

Implementation of the Provider.test_connection/2 callback

Types

s3_option()
s3_option ::
  {:access_key_id, String.t} |
  {:base_url, String.t} |
  {:bucket, String.t} |
  {:host, String.t} |
  {:https, boolean} |
  {:port, integer} |
  {:region, String.t} |
  {:secret_access_key, String.t}

Options for creating an Filesystem provider.

Functions

default(options \\ [])
default([s3_option]) ::
  {:ok, Belt.Provider.configuration} |
  {:error, term}

Creates a new S3 provider configuration with default credentials.

Default credentials can be set in multiple ways:

  1. In the Mix.Config application configuration
  2. Using the AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY environment variables
  3. Using AWS CLI config files through ExAws
  4. Configuring ExAws with Mix.Config

Example application configuration

#config.exs
config :belt, Belt.Provider.S3,
  default: [access_key_id: "…",
            secret_access_key: "…",
            bucket: "…"]
delete(config, identifier, options)

Implementation of the Belt.Provider.delete/3 callback.

delete_all(config, options)

Implementation of the Provider.delete_all/2 callback.

delete_scope(config, scope, options)

Implementation of the Provider.delete_scope/3 callback.

get_info(config, identifier, options)

Implementation of the Belt.Provider.get_info/3 callback.

get_url(config, identifier, options)

Implementation of the Belt.Provider.get_url/3 callback.

Provider-specific options

  • presign - boolean
list_files(config, options)

Implementation of the Belt.Provider.list_files/2 callback.

new(opts)

Creates a new S3 provider configuration.

Examples

#Defaults to Amazon S3 with the us-west-2 region
iex> {:ok, config} = Belt.Provider.S3.new(access_key_id: "…", secret_access_key: "…")
...> {config.host, config.region}
{"s3.dualstack.us-west-2.amazonaws.com", "us-west-2"}

#When using Amazon S3, specifying a region will automatically set the host
iex> {:ok, config} = Belt.Provider.S3.new(region: "eu-central-1", access_key_id: "…", secret_access_key: "…")
...> {config.host, config.region}
{"s3.dualstack.eu-central-1.amazonaws.com", "eu-central-1"}

Options

  • access_key_id (required) - String.t
  • secret_access_key (required) - String.t
  • base_url - String.t: :unavailable,
  • host - String.t: - Default: s3.amazonaws.com,
  • region - String.t - Default: "us-west-2"
  • port - String.t: - Default: 443,
  • bucket (required) - String.t,
  • https - String.t: - Default: true
store(config, file_source, options)

Implementation of the Belt.Provider.store/3 callback.

store_data(config, iodata, options)

Implementation of the Belt.Provider.store_data/3 callback.

test_connection(config, options)

Implementation of the Provider.test_connection/2 callback.