s3Download

Downloads an object from an S3 (or S3-compatible) bucket. When a target path is supplied, the bytes are written to that local file and true is returned; otherwise the body is returned as a UTF-8 string.

s3Download(bucket, object [, target, charset, accessKeyId, secretKey, host]) → returns any

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

Argument Reference

bucket string
Required

The name of the S3 bucket to download from.

object string
Required

The object key to download.

target string

Optional local file path to write the object bytes to. When omitted, the body is returned as a string instead.

charset string

Character encoding to use when decoding the body (informational; bodies are decoded as UTF-8).

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 s3Download function

Writes the object body to disk and returns true on success.

ok = s3Download("my-bucket", "logs/today.txt", expandPath("./today.txt"));

Without a target path, the body is returned directly.

content = s3Download("my-bucket", "logs/today.txt");

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

Fork me on GitHub