Reading and Writing Blobs

Val Town comes with blob storage built-in. It allows for storing any data: text, JSON, images

The blob helper can be imported from any val.
pomdtr/reading_and_writing_blobs
import { blob } from "https://esm.town/v/std/blob";
New blobs are created using setJSON.
pomdtr/reading_and_writing_blobs
await blob.setJSON("key", { value: 1 });
setJSON can be used to retrieve a specific blob.
pomdtr/reading_and_writing_blobs
const value = blob.getJSON("key");
console.log(value);
The lower level set and get can be used to store non-JSON or binary data.
pomdtr/reading_and_writing_blobs
const resp = await fetch("https://picsum.photos/600/300");
await blob.set("image", resp.body);
const image = await blob.get("image");

Additional resources: