View Source ExTealDirectUpload.Uploader (ExTealDirectUpload v1.2.1)

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.

Generates a pre-signed URL for uploading a file to S3.

Returns a json object with url and credentials properties.

Link to this section Functions

Link to this function

%ExTealDirectUpload.Uploader{}

View Source (struct)

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

Generates a pre-signed URL for uploading a file to S3.

This function takes an Uploader struct as an argument and returns a map containing the pre-signed URL, content type, URL, and path of the file to be uploaded.

The pre-signed URL is generated using the ExAws.S3.presigned_url/5 function with a default expiration time of 3600 seconds (1 hour). The query_params map is used to specify the AWS4-HMAC-SHA256 algorithm for signing the request.

The returned map includes the following keys:

  • presign_url: The pre-signed URL for the upload.
  • content_type: The MIME type of the file being uploaded.
  • url: The full URL of the file in the S3 bucket.
  • path: The path of the file in the S3 bucket.

This function is used to generate the necessary information for a client-side multipart POST to S3.

Returns a json object with url and credentials properties.

  • url - the form action sURL
  • credentials - name/value pairs for hidden input fields