s3GeneratePresignedURL

Generates a presigned URL that grants temporary, signed access to an object in an S3 (or S3-compatible) bucket. The expireDate argument accepts a datetime (the URL is valid until that instant) or a plain number of minutes; it defaults to 15 minutes.

s3GeneratePresignedURL(bucket, object [, expireDate, httpMethod, accessKeyId, secretKey, host]) → returns string

This function requires RustCFML.  Not supported on Lucee, Adobe ColdFusion, etc.

Argument Reference

bucket string
Required

The name of the S3 bucket containing the object.

object string
Required

The object key the URL will grant access to.

expireDate any
Default: 15

Expiry: a datetime (URL valid until that instant) or a number of minutes. Defaults to 15 minutes.

httpMethod string
Default: GET

HTTP method the presigned URL is valid for. Defaults to GET.

accessKeyId string

Inline AWS access key id. Overrides credentials from Application.cfc and environment variables.

secretKey string

Inline AWS secret access key.

host string

Inline endpoint URL for S3-compatible providers (e.g. Cloudflare R2, MinIO).

Examples
Sample code invoking the s3GeneratePresignedURL function

Creates a URL that expires in 60 minutes.

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

The fourth argument selects the HTTP method.

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

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

Fork me on GitHub