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 }Required

The file to link to: bucket/key as one string, such as invoices/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.attachmentboolean

true to have a browser save the file under its name, false to let the browser show it. true when you leave it out, or false when you give a preset.

options.presetstring

The name of a preset to resize an image to, such as thumb. 1 to 64 characters.

options.signalAbortSignal

Cancels the call when it aborts. The promise then rejects with aborted.

options.timeoutMsnumber

The longest each request may take, in milliseconds. The client’s timeoutMs when 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.

CodeWhen
validation_failedThe path or an option is wrong. issues names each field, such as path.key
not_foundThe bucket, the file, or the preset does not exist
taken_downWe took the file or its bucket down because it broke our terms
forbiddenThe API key may not download files

Every call can also fail with the codes listed on SpaceError, such as timeout and network_error.

Example

app/invoices/[number]/route.ts
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:

thumbnail.ts
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