ex_aws_s3_direct_upload v1.0.0 ExAws.S3.DirectUpload View Source

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 :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 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

Link to this function %ExAws.S3.DirectUpload{} View Source (struct)

The S3DirectUpload 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 uploaded
  • mimetype the mimetype of the file being uploaded
  • path the path where the file will be uploaded in the bucket

Fields that can be over-ridden are:

  • acl defaults to public-read

Returns a map with url and credentials keys.

  • url - the form action URL
  • credentials - 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.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 URL
  • credentials - name/value pairs for hidden input fields