trunk v0.0.1 Trunk.Storage.S3
A Trunk.Storage
implementation for Amazon’s S3 service.
Link to this section Summary
Functions
Generates a URL to the S3 object
Deletes the file from Amazon S3
Saves the file to Amazon S3
Link to this section Functions
Link to this function
build_uri(directory, filename, opts \\ [])
Generates a URL to the S3 object
directory
- The directory (will be combined with thefilename
to form the S3 key.filename
- The name of the file (will be combined with thedirectory
to form the S3 key.opts
- The options for the storage systembucket:
(required) The S3 bucket in which to store the object.virtual_host:
(optional) boolean indicator whether to generate a virtual host style URL or not.signed:
(optional) boolean whether to sign the URL or not.ex_aws:
(optional) override options forex_aws
Example:
Trunk.Storage.S3.build_url("path/to", "file.ext", bucket: "my-bucket")
#=> "https://s3.amazonaws.com/my-bucket/path/to/file.ext"
Trunk.Storage.S3.build_url("path/to", "file.ext", bucket: "my-bucket", virtual_host: true)
#=> "https://my-bucket.s3.amazonaws.com/path/to/file.ext"
Trunk.Storage.S3.build_url("path/to", "file.ext", bucket: "my-bucket", signed: true)
#=> "https://s3.amazonaws.com/my-bucket/path/to/file.ext?X-Amz-Algorithm=AWS4-HMAC-SHA256&…"
Link to this function
delete(directory, filename, opts \\ [])
Deletes the file from Amazon S3.
directory
- The directory (will be combined with thefilename
to form the S3 key.filename
- The name of the file (will be combined with thedirectory
to form the S3 key.opts
- The options for the storage systembucket:
(required) The S3 bucket in which to store the objectex_aws:
(optional) override options forex_aws
Example:
The file will be removed from s3.amazonaws.com/my-bucket/path/to/file.ext
Trunk.Storage.S3.delete("path/to/", "file.ext", bucket: "my-bucket")
Link to this function
save(directory, filename, source_path, opts \\ [])
Saves the file to Amazon S3.
directory
- The directory (will be combined with thefilename
to form the S3 key.filename
- The name of the file (will be combined with thedirectory
to form the S3 key.source_path
- The full path to the file to be stored. This is a path to the uploaded file or a temporary file that has undergone transformationopts
- The options for the storage systembucket:
(required) The S3 bucket in which to store the objectex_aws:
(optional) override options forex_aws
Example:
The file will be saved to s3.amazonaws.com/my-bucket/path/to/file.ext
Trunk.Storage.S3.save("path/to/", "file.ext", "/tmp/uploaded_file.ext", bucket: "my-bucket")