space.fs.url()
Get a download link for a file that works for 15 minutes, to hand to a browser or another service.
Gets a link to a file that anyone holding it can use for 15 minutes. Use it to let a customer download an invoice, or to show a resized photo, without sending the file through your server. To read the file in your own code, use space.fs.read().
space.fs.url(
path: string | { bucket: string; key: string },
options?: {
attachment?: boolean
preset?: string
signal?: AbortSignal
timeoutMs?: number
}
): Promise<Link>Parameters
pathstring | { bucket, key }The file to link to:
bucket/keyas one string, such asinvoices/2026/0001.pdf, or an object such as{ bucket: "invoices", key: "2026/0001.pdf" }.- The bucket is 3 to 63 lowercase letters, digits, and single hyphens, starting and ending with a letter or digit.
- The key is 1 to 1,024 bytes. It cannot start or end with
/, hold//, have a folder named.or.., or hold control characters.
options.attachmentbooleantrueto have a browser save the file under its name,falseto let the browser show it.truewhen you leave it out, orfalsewhen you give apreset.options.presetstringThe name of a preset to resize an image to, such as
thumb. 1 to 64 characters.options.signalAbortSignalCancels the call when it aborts. The promise then rejects with
aborted.options.timeoutMsnumberThe longest each request may take, in milliseconds. The client’s
timeoutMswhen you leave it out, 30,000 by default.
Returns
A promise for a Link. Fetch its url with its method and every header in headers, before expiresAt.
Anyone with the link can download the file until it expires, so give it only to the person it is for. See Keep links private.
Errors
The promise rejects with a SpaceError. The call never throws before it returns the promise, and when an argument is wrong, nothing is sent.
| Code | When |
|---|---|
validation_failed | The path or an option is wrong. issues names each field, such as path.key |
not_found | The bucket, the file, or the preset does not exist |
taken_down | We took the file or its bucket down because it broke our terms |
forbidden | The API key may not download files |
Every call can also fail with the codes listed on SpaceError, such as timeout and network_error.
Example
import { space } from "digitospace"
export async function GET(
request: Request,
{ params }: { params: Promise<{ number: string }> }
) {
const { number } = await params
const link = await space.fs.url(`invoices/2026/${number}.pdf`)
return Response.redirect(link.url, 302)
}Show a small copy of a product photo in a page:
import { space } from "digitospace"
const link = await space.fs.url("products/kanga-blue.jpg", { preset: "thumb" })
console.log(`<img src="${link.url}" alt="Blue kanga">`)
console.log(`Works until ${link.expiresAt}`)Last updated