Val Town is a collaborative website to build and scale JavaScript apps.
Deploy APIs, crons, & store data – all from the browser, and deployed in miliseconds.
Blob Storage - Docs ↗
Val Town comes with blob storage built-in. It allows for storing any data, like text, JSON, or images. You can access it via std/blob
.
Blob storage is scoped globally to your account. If you set a blob in one val, you can retrieve it by the same key in another val. It's backed by Cloudflare R2.
- Blob Storage in Settings – built-into Val Town - list, download, delete blobs
- Blob Admin – search, view, edit, upload blobs – built in a val – easy to customize in Val Town!
import { blob } from "https://esm.town/v/std/blob";
let blobDemo = await blob.getJSON("myKey");
console.log(blobDemo); // returns `undefined` if not found
import { blob } from "https://esm.town/v/std/blob";
await blob.setJSON("myKey", { hello: "world" });
import { blob } from "https://esm.town/v/std/blob";
let allKeys = await blob.list();
console.log(allKeys);
const appKeys = await blob.list("app_");
console.log(appKeys); // all keys that begin with `app_`
- Counter
- RSS Notifications (saving the last run time)
- Picture: Save & Read
blob.get
can throwValTownBlobNotFoundError
- Any method can throw
ValTownBlobError
for unexpected errors.
Our Blob SDK also includes some utility functions to make working with blobs easier.
import { blob } from "https://esm.town/v/std/blob";
await blob.copy("myKey", "myKeyCopy");
We provide access to the lower-level getter and setters, which are useful if you are storing non-JSON or binary data, need to stream in your response or request data, or do anything else lower-level.
async get(key: string)
: Retrieves a blob for a given key.async set(key: string, value: string | BodyInit)
: Sets the blob value for a given key. See BodyInit.
- Blob-stored data counts towards your total Val Town storage – 10mb on the free plan and 1gb on pro. Check our pricing page to learn more.
- Keys for blobs can be up to 512 characters long.
Migrated from folder: blob/blob