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
Options for creating an Filesystem provider.
Link to this section Functions
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:
- In the
Mix.Config
application configuration - Using the
AWS_ACCESS_KEY_ID
andAWS_SECRET_ACCESS_KEY
environment variables - Using AWS CLI config files through
ExAws
- Configuring
ExAws
withMix.Config
Example application configuration
#config.exs
config :belt, Belt.Provider.S3,
default: [access_key_id: "…",
secret_access_key: "…",
bucket: "…"]
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.list_files/2
callback.
new([s3_option()]) :: {:ok, Belt.Provider.configuration()}
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
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.