s3Download

Downloads an object from an S3 bucket. It can save the object to a file, pass it to a function in parts, or return its content.

s3Download(bucketName, objectName [, target, charset, accessKeyId, secretAccessKey, host, timeout]) → returns any

Argument Reference

bucketName string
Required

The bucket name.

objectName string
Required

The object key.

target any

Where the data goes: a file object from fileOpen(path, "write"), or a function that receives the data in parts. The function's argument name sets how the data is split: line, string{size} or binary{size}. Return false from it to stop. When omitted, the content is returned.

charset string

The charset of the content.

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. target is a file path, and the function returns true when it saves to a file. Doesn't list timeout.

Examples
Sample code invoking the s3Download function

Writes the object to the file.

s3Download("my-bucket", "logs/today.txt", fileOpen(expandPath("./today.txt"), "write"));

Without a target, the content is returned.

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