Class: S3

S3

new S3(AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY)

Class representing S3 functions. Standard environment variables the AWS-SDK expects. need to be present.
Parameters:
Name Type Description
AWS_ACCESS_KEY_ID should be set via env variable
AWS_SECRET_ACCESS_KEY should be set via env variable
Source:

Methods

createS3Policy(contentType, acl, bucket) → {Promise}

Generates a policy for browser uploads
Parameters:
Name Type Description
contentType string Mime type for file to be uploaded.
acl string acl type for file to be uploaded. either 'public-read' or 'private' @default is 'private'
bucket string Optional. Will use bucket if provided, or will use bucket passed into constructor if passed. - Optional. Will use bucket if provided, or will use bucket passed into constructor if passed.
Source:
Returns:
Base64 encoded representation of policy
Type
Promise

deleteS3Object(key, bucket) → {Promise}

Parameters:
Name Type Description
key string Required
bucket string Optional. Will use bucket if provided, or will use bucket passed into constructor if passed. - Optional. Will use bucket if provided, or will use bucket passed into constructor if passed.
Source:
Returns:
Type
Promise

download(key, bucket) → {Promise}

Parameters:
Name Type Description
key string ex: 'processed/kitty.png'. Required.
bucket string Optional. Will use bucket if provided, or will use bucket passed into constructor if passed.
Source:
Returns:
- Resolves to promise wih with buffer representation of download. Buffer can be used as a stream or written to a file.
Type
Promise

getExpiryTime() → {string}

Get expiration time for S3 policy
Source:
Returns:
returns expiration time for S3 policy
Type
string

getSignedUrl(key, expiration, bucket) → {Promise}

Parameters:
Name Type Description
key string file key. ex: 'deliverables/myfile.docx'
expiration number How long the signed url should last in minutes. leave null for 20 minutes.
bucket string Optional. Will use bucket if provided, or will use bucket passed into constructor.
Source:
Returns:
- Signed URL
Type
Promise

upload(body, key, contentType, bucket, acl) → {Promise}

Parameters:
Name Type Description
body buffer Buffer of the file to be uploaded. Must be a valid buffer.
key string key of the file to be uploaded.
contentType string mime type of the file to be upload.
bucket string Optional. Will use bucket if provided, or will use bucket passed into constructor if passed.
acl string Optional. ACL to use. Defaults to private.
Source:
Returns:
Type
Promise