Skip to content
Tutorials Center
My learning

Topics

Lesson 24 of 37 ยท Storage and Data

Object Storage and Blobs

Store uploads and generated files with Vercel Blob and Netlify Blobs: keys, content types, public versus private access, size limits, listing and cleaning up, with a runnable stand-in.

A deployment is read-only: you cannot write a new file into it while the site is running. Anything that changes at run time, such as user uploads, generated PDFs or a cached API response, needs somewhere else to live. For files and blobs of data, both platforms offer object storage that your functions can read and write.

The platform services cannot run on this site. The API shapes below are described from documentation and may gain options over time: check the current docs before copying. The runnable code is a JavaScript stand-in for the same ideas (keys, metadata, listing).

Why a filesystem is not enough

Serverless functions run on short-lived machines. You may write to a temporary directory (such as /tmp) during one invocation, but it can vanish at any moment and is not shared between invocations running in parallel. Object storage solves this with a durable, shared store addressed by key.

An object is: a key (a string like avatars/42.png), its bytes, a content type, and optional metadata. There are no real folders: avatars/ is just a prefix, but you can list by prefix to behave as if there were.

Vercel Blob

Vercel Blob stores files and serves them from a CDN URL. You use the @vercel/blob package from a function or route handler. A read-only sketch:

JavaScript
import { put, list, del } from "@vercel/blob";

// upload from a server route
const blob = await put("avatars/42.png", fileOrBuffer, {
  access: "public",          // a CDN URL anyone with the link can fetch
  contentType: "image/png",
});
console.log(blob.url);       // store this URL in your database

const { blobs } = await list({ prefix: "avatars/" });
await del(blob.url);

Points to know:

  • A read-write token is injected into your project as an environment variable when you create the store. Keep it server-side only and treat it like any other secret.
  • Large files can be uploaded directly from the browser with a client-upload flow, so the bytes never pass through a function and avoid its request-size limit. Your server issues a short-lived upload token.
  • Stores can be public or (in newer versions of the product) private; choose per store and per use.
  • Limits on file size, requests per month and total storage depend on the plan.

Netlify Blobs

Netlify Blobs is a key-value object store available in functions and edge functions, scoped by store name. The @netlify/blobs package provides:

JavaScript
import { getStore } from "@netlify/blobs";

const store = getStore("avatars");
await store.set("42", fileBytes, { metadata: { contentType: "image/png" } });
const data = await store.get("42", { type: "arrayBuffer" });
const { blobs } = await store.list({ prefix: "4" });
await store.delete("42");

Inside a Netlify function the credentials are provided automatically; outside one you pass a site ID and token. Blobs have a deploy-scoped variant (getDeployStore) for data that should be tied to a specific deploy, versus the site-wide store that persists across deploys.

Choosing where bytes live

Need Good choice
Files that ship with the site (logo, fonts) the repository's public/ or static folder
User uploads, generated files Blob / Blobs, or your own bucket (S3, R2)
Structured records with queries a database (Databases from Serverless)
Small config read at the edge Edge Config and key-value stores

You can also use any S3 compatible bucket from your functions: the platform storage is a convenience, not a requirement.

Object storage

Key A string like avatars/42.png.
Bytes The file contents.
Metadata Content type and custom tags.
List Browse by key prefix.

No real folders, only prefixes.

1 / 2

A blob store stand-in

This in-memory store has set, get, list and delete with prefix listing, content type metadata and a size cap, so you can practice the access patterns used in real code.

JS Blob store stand-in

Press Run (or Ctrl + Enter) to see the console output here.

No output.

Safe uploads

A pattern worth practicing is validating before you store: check the content type against an allow-list, enforce a maximum size and build the key yourself rather than trusting the file name the user sent (a name like ../../secret or a name with spaces causes trouble).

JS Upload validation stand-in

Press Run (or Ctrl + Enter) to see the console output here.

No output.

Practical advice

  • Store the URL or key in a database row; the blob store is not a search index.
  • Set a sensible Cache-Control and content type so browsers and the CDN behave.
  • Delete what you no longer need: storage and bandwidth are billed.
  • Never accept a client's file name as the key without cleaning it.
  • Treat blob tokens like passwords; never ship them to the browser.

Check your understanding

Quick check ยท 4 questions

of 4 answered You scored / 4 ยท perfect!

  1. 1. Why can a function not simply write uploads to its own disk?

    Any local files exist only for that instance's lifetime. Durable shared data belongs in object storage or a database.
  2. 2. What is a key prefix used for?

    Object stores have no real directories, so listing by prefix such as avatars/ emulates them.
  3. 3. Why use a client-side direct upload for large files?

    The server only issues a short-lived token; the browser sends the file straight to storage.
  4. 4. Where should the original user-supplied file name be used when building the key?

    File names can contain path tricks or odd characters. Build keys from IDs you control.

Summary

  • Deployments are read-only; run-time files need object storage.
  • Vercel Blob (put, list, del) and Netlify Blobs (getStore, set, get) store bytes by key.
  • Keys are flat strings; prefixes emulate folders.
  • Validate type and size, and build keys yourself.
  • Keep tokens on the server and clean up unused objects.

Next: Edge Config and Key-Value Stores