SQLPage allows you to upload and download files from S3-compatible object storage services, such as AWS S3, MinIO, Cloudflare R2, Google Cloud Storage, and others.
To enable S3 integration, you need to add the following configuration to your sqlpage/sqlpage.json file.
{
"s3_bucket": "my-app-uploads",
"s3_region": "us-east-1",
"s3_access_key": "AKIAIOSFODNN7EXAMPLE",
"s3_secret_key": "wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY"
}If you are using MinIO, you need to specify the s3_endpoint URL.
{
"s3_bucket": "my-local-bucket",
"s3_region": "us-east-1",
"s3_endpoint": "http://localhost:9000",
"s3_access_key": "minioadmin",
"s3_secret_key": "minioadmin"
}Note: For MinIO,
s3_regionis often required by the client SDK but ignored by the server. You can usually set it tous-east-1.
| Parameter | Description | Required |
|---|---|---|
s3_bucket |
The default bucket name to use for operations. | Yes (unless specified in function calls) |
s3_region |
The AWS region (e.g., us-east-1, eu-west-1). |
Yes |
s3_endpoint |
The endpoint URL. Required for non-AWS providers (MinIO, R2, etc.). | No |
s3_access_key |
Your access key ID. | Yes |
s3_secret_key |
Your secret access key. | Yes |
Uploads data to an S3 bucket.
Signature: sqlpage.upload_to_s3(bucket, data, key)
- bucket (string, optional): The name of the bucket. If
NULL, thes3_bucketfrom configuration is used. - data (string): The data to upload. This can be:
- A file path (e.g., from
sqlpage.uploaded_file_path). - A base64-encoded string.
- A file path (e.g., from
- key (string): The path/name of the object in the bucket (e.g.,
uploads/image.png).
Returns: The S3 URI of the uploaded object (e.g., s3://bucket/key).
Example:
-- Upload a file submitted via a form
SELECT sqlpage.upload_to_s3(
NULL, -- Use default bucket from config
sqlpage.uploaded_file_path('profile_picture'),
'users/' || $user_id || '/profile.png'
);Generates a presigned URL to download a file from an S3 bucket. The URL is valid for 1 hour.
Signature: sqlpage.get_from_s3(bucket, key)
- bucket (string, optional): The name of the bucket. If
NULL, thes3_bucketfrom configuration is used. - key (string): The path/name of the object in the bucket.
Returns: A temporary HTTP URL that allows downloading the file.
Example:
SELECT 'text' as component,
'Download Profile Picture' as contents;
SELECT 'button' as component;
SELECT 'Download' as title,
sqlpage.get_from_s3(NULL, 'users/' || $user_id || '/profile.png') as link;