ex_aws_s3_direct_upload v1.0.4 ExAws.S3.DirectUpload View Source
Pre-signed S3 upload helper for client-side multipart POSTs, with support for using AWS Instance Roles, which produce temporary credentials. This approach reduces the number of ENV variables to pass, among other benefits.
See:
Browser-Based Upload using HTTP POST (Using AWS Signature Version 4)
Task 3: Calculate the Signature for AWS Signature Version 4
This module does not require any further configuration other than the default already in place, when using ex_aws or ex_aws_s3.
The default configuration is as follows:
config :ex_aws,
access_key_id: [{:system, "AWS_ACCESS_KEY_ID"}, :instance_role],
secret_access_key: [{:system, "AWS_SECRET_ACCESS_KEY"}, :instance_role]
The Authentication Resolver will look for credentials in ENV variables, and fall back to Instance Role.
Link to this section Summary
Functions
The S3DirectUpload struct represents the data necessary to
generate an S3 pre-signed upload object
Returns a map with url and credentials keys
Returns a json object with url and credentials properties
Link to this section Functions
The S3DirectUpload struct represents the data necessary to
generate an S3 pre-signed upload object.
The required fields are:
file_namethe name of the file being uploadedmimetypethe mimetype of the file being uploadedpaththe path where the file will be uploaded in the bucketbucketthe name of the bucket to which to upload the file
Fields that can be over-ridden are:
acldefaults topublic-read
Returns a map with url and credentials keys.
url- the form action URLcredentials- name/value pairs for hidden input fields
Examples
iex> %ExAws.S3.DirectUpload{file_name: "image.jpg", mimetype: "image/jpeg", path: "path/to/file", bucket: "s3-bucket"}
...> |> ExAws.S3.DirectUpload.presigned
...> |> Map.get(:url)
"https://s3-bucket.s3.us-east-1.amazonaws.com"
iex> %ExAws.S3.DirectUpload{file_name: "image.jpg", mimetype: "image/jpeg", path: "path/to/file", bucket: "s3-bucket"}
...> |> ExAws.S3.DirectUpload.presigned
...> |> Map.get(:credentials) |> Map.get(:"x-amz-credential")
"123abc/20170101/us-east-1/s3/aws4_request"
iex> %ExAws.S3.DirectUpload{file_name: "image.jpg", mimetype: "image/jpeg", path: "path/to/file", bucket: "s3-bucket"}
...> |> ExAws.S3.DirectUpload.presigned
...> |> Map.get(:credentials) |> Map.get(:key)
"path/to/file/image.jpg"
Returns a json object with url and credentials properties.
url- the form action URLcredentials- name/value pairs for hidden input fields