s3GenerateURI

Builds a non-signed, canonical URI for an S3 (or S3-compatible) object. No network call is made. style may be virtualhost (default) or path; secure controls the https/http scheme; host overrides the endpoint (e.g. for Cloudflare R2 or MinIO).

s3GenerateURI(bucket [, object, style, secure, 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.

object string

The object key. When omitted, a bucket-level URI is returned.

style string
Default: virtualhost

Addressing style: virtualhost (bucket as subdomain, default) or path (bucket as first path segment).
Values:
  • virtualhost
  • path

secure boolean
Default: true

Whether to use https (true, default) or http.

host string

Endpoint host to use instead of the default AWS endpoint (e.g. an R2 or MinIO host).

Examples
Sample code invoking the s3GenerateURI function

Virtual-host style against the default endpoint.

uri = s3GenerateURI("my-bucket", "reports/q3.pdf");

Expected Result: https://my-bucket.s3.amazonaws.com/reports/q3.pdf

Useful for providers that do not serve bucket subdomains.

uri = s3GenerateURI("my-bucket", "reports/q3.pdf", "path", true, "minio.example.com");

Expected Result: https://minio.example.com/my-bucket/reports/q3.pdf

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

Fork me on GitHub