StorageStorage ServicesVercel Blob

Vercel Blob

Last updated:

Vercel Blob Storage

Overview

Vercel Blob Storage is a serverless object storage service optimized for edge deployments. It provides fast, global access to files with automatic CDN distribution.

Installation

npm install @vercel/blob
yarn add @vercel/blob
pnpm add @vercel/blob

Usage

import { VercelBlobStorage } from "@visulima/storage/provider/vercel";

const storage = new VercelBlobStorage({
    token: process.env.BLOB_READ_WRITE_TOKEN,
    metaStorageConfig: { directory: "/tmp/upload-metafiles" },
});

Configuration

Environment Variables

// Set BLOB_READ_WRITE_TOKEN or VERCEL_BLOB_TOKEN
process.env.BLOB_READ_WRITE_TOKEN = "vercel_blob_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx";

const storage = new VercelBlobStorage({
    // Token is automatically read from environment
});

With Token

const storage = new VercelBlobStorage({
    token: "vercel_blob_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
});

Advanced Configuration

const storage = new VercelBlobStorage({
    token: process.env.BLOB_READ_WRITE_TOKEN,
    multipart: true, // Enable multipart uploads for large files
    multipart: 10 * 1024 * 1024, // Enable multipart for files > 10MB
    retryConfig: {
        maxRetries: 3,
        initialDelay: 1000,
    },
    expiration: {
        maxAge: "7d",
        purgeInterval: "1h",
    },
});

Features

  • Global CDN: Automatic CDN distribution for fast access
  • Serverless: Optimized for edge deployments
  • Multipart Uploads: Support for large files
  • Automatic Retry: Built-in retry mechanism for transient failures

Basic Operations

// Create a file
const file = await storage.create({
    contentType: "image/jpeg",
    metadata: { filename: "photo.jpg" },
});

// Write data
await storage.write({
    id: file.id,
    body: imageStream,
    contentLength: imageSize,
});

// Get file
const fileData = await storage.get({ id: file.id });

// Delete file
await storage.delete({ id: file.id });

URL Generation

Vercel Blob automatically generates public URLs:

const file = await storage.get({ id: "file-id" });

// file.url - Public URL
// file.downloadUrl - Download URL
// file.pathname - File pathname

Best Practices

  1. Use environment variables - Store tokens securely
  2. Enable multipart for large files - Better performance for files > 10MB
  3. Configure retry - Handle transient failures
  4. Use CDN URLs - Leverage Vercel's global CDN
  5. Monitor usage - Track storage and bandwidth usage
Support

Contribute to our work and keep us going

Community is the heart of open source. The success of our packages wouldn't be possible without the incredible contributions of users, testers, and developers who collaborate with us every day.Want to get involved? Here are some tips on how you can make a meaningful impact on our open source projects.

Ready to help us out?

Be sure to check out the package's contribution guidelines first. They'll walk you through the process on how to properly submit an issue or pull request to our repositories.

Submit a pull request

Found something to improve? Fork the repo, make your changes, and open a PR. We review every contribution and provide feedback to help you get merged.

Good first issues

Simple issues suited for people new to open source development, and often a good place to start working on a package.
View good first issues