Belt v0.5.1 Belt.Provider.S3 View Source

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]}

Link to this section 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

Link to this section Types

Link to this type s3_option() View Source
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.

Link to this section Functions

Link to this function default(options \\ []) View Source
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: "…"]
Link to this function delete(config, identifier, options) View Source

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

Link to this function delete_all(config, options) View Source

Implementation of the Provider.delete_all/2 callback.

Link to this function delete_scope(config, scope, options) View Source

Implementation of the Provider.delete_scope/3 callback.

Link to this function get_info(config, identifier, options) View Source

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

Link to this function get_url(config, identifier, options) View Source

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

Provider-specific options

  • presign - boolean
Link to this function list_files(config, options) View Source

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

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
Link to this function store(config, file_source, options) View Source

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

Link to this function store_data(config, iodata, options) View Source

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

Link to this function test_connection(config, options) View Source

Implementation of the Provider.test_connection/2 callback.