Loading...
Loading...
Use when a val needs simple key/value persistence — JSON documents, cached responses, uploaded files, or binary assets. Covers the std/blob API, listing and deleting keys, account-global or val scoping, and storage limits.
npx skill4agent add val-town/plugins blob-storagestd/blobstd/sqliteglobal.tsmain.tsmain.ts/**
* Importing from `main.ts` provides an interface to val-scoped blobs.
*/
import { blob } from "https://esm.town/v/std/blob/main.ts";/**
* Importing from `global.ts` provides a blob interface that is scoped
* to your account.
*/
import { blob } from "https://esm.town/v/std/blob/global.ts";
/**
* This entrypoint is also available as `v/std/blob`. This is common
* in older vals.
*/
import { blob } from "https://esm.town/v/std/blob";blobimport { blob } from "https://esm.town/v/std/blob/main.ts";
await blob.setJSON("config", { theme: "dark", count: 0 });
const config = await blob.getJSON("config");
// config = { theme: "dark", count: 0 }, or undefined if the key doesn't existgetJSONundefinedconst config = (await blob.getJSON("config")) ?? { theme: "light", count: 0 };setgetBodyInitgetResponse.text().json().arrayBuffer().blob()await blob.set("logo.png", imageBytes); // string | BodyInit (Blob, ArrayBuffer, ReadableStream, …)
const res = await blob.get("logo.png");
const bytes = await res.arrayBuffer();getJSONgetValTownBlobNotFoundErrortry/catchconst entries = await blob.list("user_"); // optional key prefix filter
// entries = [{ key, size, lastModified }, …]
for (const { key } of entries) {
await blob.delete(key);
}
await blob.copy("config", "config.bak"); // duplicate under a new key
await blob.move("draft", "published"); // rename / relocatelist(prefix?){ key: string; size: number; lastModified: string }std/sqlitestoreBlobreadBloblistBlobsdeleteBloborg{ key: "myapp:config", org: "some-org" }storeBlobblob.setfeature:subkeylistgetJSONundefinedgetValTownBlobNotFoundError