Skip to content
Jennifer Programming Language

s3presign API reference

Presigned URLs for S3-compatible object storage (AWS S3 / MinIO / R2 / B2), with no network: the local half of the s3 module. A presigned URL grants one HTTP method on one object for a limited time, signed with AWS Signature Version 4 query parameters, so any HTTP client (a browser, curl, another service) can use it without the secret key. Building one sends nothing, and this module imports no network module, so it runs on both binaries.

It is a subset of s3 with the same names: Client, connect, S3Error and presign behave as they do there, and share its signing code, so a program that only presigns moves between the two by changing the import. connect only validates the endpoint and builds the value; nothing is contacted.

Import with import "s3presign.j" as s3presign;. See the s3presign guide for prose and examples.

Contents

NameWhat it is
connectBuild a client value for an S3 endpoint, as s3.connect does: the endpoint is http:// or https:// plus...
presignBuild a presigned URL that grants time-limited access to an object without exposing the secret key, using S...
Clientstruct: An S3 endpoint and its credentials: the endpoint (scheme + host, no trailing slash), the signing region, an...
S3Errorstruct: A failed presign: a malformed endpoint, bucket name, key or expiry.

Functions

connect

jennifer
s3presign.connect(
    endpoint as string,
    region as string,
    accessKey as string,
    secretKey as string)

Build a client value for an S3 endpoint, as s3.connect does: the endpoint is http:// or https:// plus a host (a name, an IPv4 address or a bracketed IPv6 address) and an optional port; one trailing / is dropped. A path, a query, a fragment, userinfo or a malformed host or port throws. Nothing is contacted.

endpoint
the base URL
region
the signing region
accessKey
the access key id
secretKey
the secret access key
Returns Client
the client value
Throws S3Error
kind "s3" for a malformed endpoint

presign

jennifer
s3presign.presign(
    client as Client,
    method as string,
    bucketName as string,
    key as string,
    expiresSeconds as int)

Build a presigned URL that grants time-limited access to an object without exposing the secret key, using SigV4 query-signing (X-Amz-* query parameters) stamped with the current time. The URL works from any HTTP client until it expires.

client
the client
method
the HTTP method the URL authorizes (e.g. "GET", "PUT")
bucketName
the bucket
key
the object key
expiresSeconds
the validity window in seconds (1 to 604800 = 7 days)
Returns string
the presigned URL
Throws S3Error
kind "s3" for an expiry outside 1..604800, a bad bucket name or an empty key

Structs

Client

An S3 endpoint and its credentials: the endpoint (scheme + host, no trailing slash), the signing region, and the access-key pair. The same shape as s3.Client; timeoutMs and allowInsecureHttp only matter to s3's requests. Value-semantic; build with connect.

jennifer
def struct Client {
    endpoint as string,
    region as string,
    accessKey as string,
    secretKey as string,
    timeoutMs as int,
    allowInsecureHttp as bool
};
endpoint
e.g. "https://s3.us-east-1.amazonaws.com" or "http://localhost:9000"
region
the signing region, e.g. "us-east-1"
accessKey
the access key id
secretKey
the secret access key
timeoutMs
per-request timeout of s3's requests (unused here); connect sets 30000
allowInsecureHttp
allow plain http:// to a non-loopback host in s3's requests (unused here)

S3Error

A failed presign: a malformed endpoint, bucket name, key or expiry. The same shape as s3.S3Error; every error of kind "s3" this module throws is one.

jennifer
def struct S3Error {
    kind as string,
    message as string,
    status as int,
    code as string,
    requestId as string
};
kind
always "s3"
message
what went wrong
status
always 0 (a local check)
code
always ""
requestId
always ""