View Source ExTealDirectUpload.Uploader (ExTealDirectUpload v1.0.2)
Pre-signed S3 upload helper for client-side multipart POSTs.
See:
Browser-Based Upload using HTTP POST (Using AWS Signature Version 4)
Task 3: Calculate the Signature for AWS Signature Version 4
This module expects three application configuration settings for the
AWS access and secret keys and the S3 bucket name. You may also
supply an AWS region (the default if you do not is
us-east-1
). Here is an example configuration that reads these from
environment variables. Add your own configuration to config.exs
.
config :ex_teal_direct_upload,
aws_access_key: System.get_env("AWS_ACCESS_KEY_ID"),
aws_secret_key: System.get_env("AWS_SECRET_ACCESS_KEY"),
aws_s3_bucket: System.get_env("AWS_S3_BUCKET"),
aws_region: System.get_env("AWS_REGION")
Link to this section Summary
Functions
The Uploader
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 Uploader
struct represents the data necessary to
generate an S3 pre-signed upload object.
The required fields are:
file_name
the name of the file being uploadedmimetype
the mimetype of the file being uploadedpath
the path where the file will be uploaded in the bucket
Fields that can be over-ridden are:
acl
defaults topublic-read
Returns a map with url
and credentials
keys.
url
- the form action URLcredentials
- name/value pairs for hidden input fields
examples
Examples
iex> %ExTealDirectUpload.Uploader{file_name: "image.jpg", mimetype: "image/jpeg", path: "path/to/file"}
...> |> ExTealDirectUpload.Uploader.presigned
...> |> Map.get(:postEndpoint)
"https://s3-bucket.s3.amazonaws.com"
iex> %ExTealDirectUpload.Uploader{file_name: "image.jpg", mimetype: "image/jpeg", path: "path/to/file"}
...> |> ExTealDirectUpload.Uploader.presigned
...> |> Map.get(:signature) |> Map.get(:"X-amz-credential")
"123abc/20170101/us-east-1/s3/aws4_request"
iex> %ExTealDirectUpload.Uploader{file_name: "image.jpg", mimetype: "image/jpeg", path: "path/to/file"}
...> |> ExTealDirectUpload.Uploader.presigned
...> |> Map.get(:signature) |> Map.get(:key)
"path/to/file/image.jpg"
Returns a json object with url
and credentials
properties.
url
- the form action sURLcredentials
- name/value pairs for hidden input fields