Guide
Downloads & Retrieval
Public URLs, pre-signed URLs, and streaming files back out
getUrl(path)
Returns a static public URL built from the driver's baseUrl (or an auto-derived default) plus the encoded path.
| Driver | URL format |
|---|---|
LocalDriver | <baseUrl>/<path>: defaults to file://<directory>/<path>. Set baseUrl to a CDN/web URL in production. |
S3Driver | <baseUrl>/<path>: virtual-hosted or path-style based on forcePathStyle. Assumes the bucket is publicly readable. |
GCSDriver | <baseUrl>/<path>: defaults to https://storage.googleapis.com/<bucket>/<path>. Assumes the object is publicly readable. |
AzureDriver | <baseUrl>/<path>: defaults to https://<account>.blob.core.windows.net/<container>/<path>. Assumes public read access. |
SupabaseDriver | The public object URL (/storage/v1/object/public/<bucket>/<path>). Works for public buckets only. |
CloudinaryDriver | The Cloudinary CDN URL for the asset. |
Pre-signed URLs
For storage without its own signed URLs, see App-signed links below.
Both S3Driver and CloudinaryDriver can sign time-limited download URLs; only LocalDriver cannot (it has no access control to gate).
S3: getPresignedUrl(path, { expiresIn }) returns a SigV4-signed GET URL: anyone with the link can download the object without credentials until it expires. Hand these out for private buckets instead of getUrl() results, which assume a publicly readable bucket.
const url = await client.getPresignedUrl("uploads/report.pdf", { expiresIn: 900 });
// https://bucket.s3.us-east-1.amazonaws.com/uploads/report.pdf?X-Amz-Algorithm=...expiresIndefaults to 3600 seconds (1 hour) and must be an integer in1..604800(AWS's 7-day cap); invalid values throw aValidationError.- Signing is done entirely with Web Crypto + your configured credentials: no SDK, no network call. Only the
hostheader is signed with anUNSIGNED-PAYLOADhash, so the URL works in any browser or client. - Works with
endpoint/forcePathStyletoo (MinIO, R2, GCS-S3), as long as the endpoint validates SigV4 presigning (MinIO does).
Cloudinary: getPresignedUrl(publicId, { expiresIn, deliveryType }) returns a signed private download URL (api.cloudinary.com/.../download) that stops working after expiresIn seconds, using the same resource-type/version/format resolution chain as getUrl. For a signed but non-expiring res.cloudinary.com URL, use CloudinaryDriver.getSignedUrl() (see the Cloudinary driver).
expiresIndefaults to 3600 seconds and must be a positive integer; no documented maximum.- Drivers that cannot presign (
LocalDriver) omit the method, andFilewayClient.getPresignedUrlthrows a clear error in that case.
App-signed links
Local disks, network disks and other storage that cannot sign URLs can still get links: your app signs them, and client.handler serves the file when the link is opened. Configure links with a secret and the public origin where the handler is mounted:
const client = new FilewayClient({
driver: new LocalDriver({ directory: "/mnt/nas/uploads" }),
links: {
secret: process.env.FILEWAY_LINK_SECRET!, // 32+ random bytes, base64: openssl rand -base64 32
origin: "https://files.myapp.com", // links are {origin}{basePath}/files/...
},
});
// app/api/fileway/[...all]/route.ts (Next.js)
export const { GET, HEAD, PUT, OPTIONS } = client.handler;
const url = await client.getPresignedUrl("reports/q3.pdf", { expiresIn: 600 });- When they are used: by default only for drivers that cannot presign (
mode: "fallback"). Withmode: "always", every driver's links go through your app, so every download is logged as an event. - Open or download: images, PDF, audio and video open in the browser by default; everything else downloads. HTML, SVG, XML and scripts never open inline unless you list the type in
links.inlineTypes. Override per link withdispositionand set the download name withfilename. - Seeking: links answer
Rangerequests with206, so video and audio players can seek. - Revoking: links cannot be revoked one by one. Use short expiries, rotate the secret (pass
secret: [newSecret, oldSecret]to keep old links working during the change, then drop the old one), or give a link anidand refuse it inlinks.check(link, request). - Bandwidth: unlike cloud presigned URLs, the bytes pass through your app.
Keep links safe
- Serve links from a separate subdomain with no login cookies (
files.myapp.com), so a malicious upload opened in the browser cannot act as your users. - Every response carries
X-Content-Type-Options: nosniffand, except for PDFs,Content-Security-Policy: sandbox; default-src 'none'. PDFs skip the policy because Chrome's PDF viewer does not render under it. - Everything that changes what is served is signed: the path, expiry, open or download, filename and
id. Changing any of them makes the link fail with403.
Download events
Each download through an app-signed link is logged as a get event that plugins receive in onEvent:
| Field | Value |
|---|---|
operation | "get" |
path | The file's path. This is the stable way to identify a file: uploads are stored at <folder>/<id>.<ext> on every driver that builds paths that way (local disk, S3, Google Cloud, Azure, Supabase), so the same upload id gives the same path on all of them. Cloudinary stores <folder>/<id>, without the extension. |
actor | "link" |
tags.linkId | The id you passed to getPresignedUrl, when you passed one. It is part of the signature, so it cannot be changed. |
outcome, durationMs, driver | As for every event. durationMs is the time to open the file, not the whole transfer. |
The event's own id is unique per event (for de-duplication); it does not identify the file.
To match a download to whatever created the link, give the link an id and tag the call that creates it with the same value. The link expires; the events keep both:
const runId = "qa-2026-11-25-checkout"; // your own id: a QA run, a share, a ticket
const url = await client.getPresignedUrl(upload.path, {
expiresIn: 600,
id: runId, // signed into the link; comes back as tags.linkId on downloads
tags: { qaRun: runId }, // on the getPresignedUrl event, with your actor
});
// In a plugin's onEvent:
// { operation: "getPresignedUrl", path, tags: { qaRun: runId }, actor: "..." } when the link is created
// { operation: "get", path, actor: "link", tags: { linkId: runId } } each time it is openedWhat is and is not logged:
- Logged: every
GETof a valid link, including each range request a video or audio player makes while seeking. - Not logged:
HEADrequests, and links refused for a bad signature, after expiry, or bylinks.check. - Cloud presigned URLs are not logged. By default S3, Google Cloud, Azure and Supabase hand out their own presigned URLs, and the download goes straight to the provider without passing through your app. Set
links: { mode: "always" }to send those downloads through your app as well, so they are logged the same way as local disk.
Download / read-back (get(path))
Every driver streams a stored file back as a WHATWG ReadableStream<Uint8Array>: the same type it accepts on upload:
const stream = await client.get("uploads/report.pdf"); // ReadableStream<Uint8Array>
const bytes = new Uint8Array(await new Response(stream).arrayBuffer());The stream is pull-based with backpressure, so files are never buffered whole on the way down. It can be piped straight to a destination (stream.pipeTo(writable)); for binary files use .arrayBuffer()/.blob() rather than .text(), which would decode binary data as UTF-8 and corrupt it.
| Driver | Behavior |
|---|---|
LocalDriver | Streams the file from disk via createReadStream → Readable.toWeb(). Throws if the file is missing or the path escapes the storage directory. |
S3Driver | Authenticated SigV4 GET; returns the response body directly. Throws with the HTTP status on failure (e.g. 404). |
GCSDriver | Authenticated GET ?alt=media; returns the response body. |
AzureDriver | Signed (Shared Key) or SAS GET; returns the response body. |
SupabaseDriver | GET on the authenticated object route; returns the response body. |
CloudinaryDriver | fetches the asset's public CDN URL and returns the response body. Throws on a non-2xx status. |
Was this page helpful?