tus_storage_s3 v0.1.0 Tus.Storage.S3

S3 (or compatible) storage backend for the Tus server

Installation

The package can be installed by adding tus_cache_redis to your list of dependencies in mix.exs:

def deps do
  [
    {:tus, "~> 0.1.1"},
    {:tus_storage_s3, "~> 0.1.0"},
  ]
end

Configuration

  • storage: Set it as Tus.Storage.S3

  • s3_bucket: The name of your bucket

  • s3_host: Optional. “s3.amazonaws.com” by default

  • s3_prefix: Optional. Prefix added to all files. Empty by default

  • s3_min_part_size: The minimum size of a single part (except the last). In Amazon S3 this is 5MB. For other, compatible services, you might want/need to change this restriction.

In order to allow this backend to function properly, the user accessing the bucket must have at least the following AWS IAM policy permissions for the bucket and all of its subresources:

s3:AbortMultipartUpload
s3:DeleteObject
s3:GetObject
s3:ListMultipartUploadParts
s3:PutObject

Furthermore, this uses the ExAWS package, so you’ll need to add valid AWS keys to its config.

config :ex_aws,
  access_key_id: [{:system, "AWS_ACCESS_KEY_ID"}, :instance_role],
  secret_access_key: [{:system, "AWS_SECRET_ACCESS_KEY"}, :instance_role]

This means it will try to resolve credentials in this order

  • a. Look for the AWS standard AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY environment variables
  • b. Resolve credentials with IAM

Consult the (ExAWS documentation)[https://hexdocs.pm/ex_aws/ExAws.html#module-aws-key-configuration] for more details.

Link to this section Summary

Functions

Add data to an already started Multipart Upload (identified by file.upload_id)

Finish a Multipart Upload

Start a Multipart Upload and store its upload_id

Delete an uploaded object

Link to this section Functions

Link to this function append(file, config, body)

Add data to an already started Multipart Upload (identified by file.upload_id).

Amazon restrict the minimum size of a single part (except the last one) to at least 5MB. If the data is smaller than that, this function returns :too_small.

That limit can be customized with the config option s3_min_part_size.

Link to this function complete_upload(file, config)

Finish a Multipart Upload

Link to this function create(file, config)

Start a Multipart Upload and store its upload_id.

Link to this function delete(file, config)

Delete an uploaded object