ScalesCms.Cms.Helpers.SimpleS3Upload (scales_cms v0.1.20)

Dependency-free S3 Form Upload using HTTP POST sigv4 https://docs.aws.amazon.com/AmazonS3/latest/API/sigv4-post-example.html

Summary

Functions

Signs a form upload. The configuration is a map which must contain the following keys

Functions

bucket()

entry_url(entry)

ext(entry)

meta(entry, uploads)

presign_entry(entry, socket)

region()

s3_filepath(entry)

sign_form_upload(opts)

Signs a form upload. The configuration is a map which must contain the following keys:

  • :region - The AWS region, such as "us-east-1"
  • :access_key_id - The AWS access key id
  • :secret_access_key - The AWS secret access key Returns a map of form fields to be used on the client via the JavaScript FormData API.

Options

  • :key - The required key of the object to be uploaded.
  • :max_file_size - The required maximum allowed file size in bytes.
  • :content_type - The required MIME type of the file to be uploaded.
  • :expires_in - The required expiration time in milliseconds from now before the signed upload expires.

Examples

{:ok, fields} =
  SimpleS3Upload.sign_form_upload(
    key: "public/my-file-name",
    content_type: "image/png",
    max_file_size: 10_000,
    expires_in: :timer.hours(1)
  )