Skip to content

Latest commit

 

History

History
93 lines (66 loc) · 2.8 KB

File metadata and controls

93 lines (66 loc) · 2.8 KB

S3 Object Storage Integration

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.

Configuration

To enable S3 integration, you need to add the following configuration to your sqlpage/sqlpage.json file.

AWS S3 Example

{
    "s3_bucket": "my-app-uploads",
    "s3_region": "us-east-1",
    "s3_access_key": "AKIAIOSFODNN7EXAMPLE",
    "s3_secret_key": "wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY"
}

MinIO Example

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_region is often required by the client SDK but ignored by the server. You can usually set it to us-east-1.

Configuration Parameters

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

Functions

sqlpage.upload_to_s3

Uploads data to an S3 bucket.

Signature: sqlpage.upload_to_s3(bucket, data, key)

  • bucket (string, optional): The name of the bucket. If NULL, the s3_bucket from 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.
  • 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'
);

sqlpage.get_from_s3

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, the s3_bucket from 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;