s3GeneratePresignedURL

Generates a presigned URL that gives temporary access to an S3 object.

s3GeneratePresignedURL(bucketNameOrPath [, objectName, expireDate, httpMethod, sseAlgorithm, sseCustomerKey, checksum, type, disposition, encoding, version, zeroByte, responseHeaders, accessKeyId, secretAccessKey, host, timeout]) → returns string

Argument Reference

bucketNameOrPath string
Required

The bucket name, or an s3:// path to a bucket or object, such as s3://mybucket/file.txt.

objectName string

The object key, when bucketNameOrPath is a bucket name.

expireDate date

When the URL expires.

httpMethod string

The HTTP method the URL is for, such as GET or PUT.

sseAlgorithm string

The server-side encryption algorithm: AES256 or KMS.

sseCustomerKey string

The customer-provided server-side encryption key.

checksum string

The base64-encoded MD5 checksum of the content.

type string

The MIME type of the content.

disposition string

The Content-Disposition value, such as attachment; filename="report.pdf".

encoding string

The Content-Encoding value, such as gzip.

version string

The object version ID, when versioning is enabled.

zeroByte boolean

When true, the object has zero-byte content.

responseHeaders struct

A struct of custom metadata headers. The x-amz-meta- prefix is added when missing.

accessKeyId string

The S3 access key ID. Defaults to the lucee.s3.accesskeyid system property or environment variable.

secretAccessKey string

The S3 secret access key. Defaults to the lucee.s3.secretaccesskey system property or environment variable.

host string

The hostname of an S3-compatible provider, without https://. Defaults to Amazon AWS.

timeout numeric
Default: 10000

The timeout in milliseconds.

Compatibility

Lucee:

Requires the S3 extension.

RustCFML:

Names the first two arguments bucket and object, and the secret key argument secretKey. expireDate also accepts a number of minutes and defaults to 15 minutes. Only expireDate and httpMethod are supported of the URL arguments, so accessKeyId is the fifth argument.

Examples
Sample code invoking the s3GeneratePresignedURL function

Creates a URL that expires in 60 minutes.

url = s3GeneratePresignedURL("my-bucket", "reports/q3.pdf", dateAdd("n", 60, now()));

The fourth argument selects the HTTP method.

url = s3GeneratePresignedURL("my-bucket", "uploads/new.txt", dateAdd("n", 15, now()), "PUT");

Signup for cfbreak to stay updated on the latest news from the ColdFusion / CFML community. One email, every friday.

Fork me on GitHub