method Storage.prototype.presign
Storage.prototype.presign(
key: string,
options: PresignOptions,
): Task<string, StoragePresignFailed | StoragePresignNotSupported>

Generate a presigned URL for direct object access.

Only available on adapters that implement PresignableAdapter (S3, GCS). Throws StoragePresignNotSupported for adapters that don't support presigning (memory, browser).

Examples

Generate a presigned URL for download

import { Storage, createS3, StoragePresignNotSupported } from "@anabranch/storage";

const storage = await Storage.connect(createS3({ bucket: "my-bucket" })).run();

const url = await storage.presign("private/file.txt", {
  expiresIn: 3600, // 1 hour
}).run();

console.log(url); // https://s3.amazonaws.com/my-bucket/private/file.txt?...

Upload with presigned PUT

const uploadUrl = await storage.presign("upload.txt", {
  expiresIn: 300,
  method: "PUT",
}).run();

// Client-side upload
await fetch(uploadUrl, {
  method: "PUT",
  body: fileData,
  headers: { "Content-Type": "text/plain" },
});

Parameters

key: string

Return Type