vercel-blob-no-undici
TypeScript icon, indicating that this package has built-in type declarations

0.22.4 • Public • Published

🍙 @vercel/blob

The Vercel Blob JavaScript API client.


👉 Quickstart SDK Reference 👈


Installation

npm install @vercel/blob

Quickstart

We have examples on the vercel.com documentation, there are two ways to upload files to Vercel Blob:

  1. Server uploads: This is the most common way to upload files. The file is first sent to your server and then to Vercel Blob. It's straightforward to implement, but you are limited to the request body your server can handle. Which in case of a Vercel-hosted website is 4.5 MB. This means you can't upload files larger than 4.5 MB on Vercel when using this method.
  2. Client uploads: This is a more advanced solution for when you need to upload larger files. The file is securely sent directly from the client (a browser for example) to Vercel Blob. This requires a bit more work to implement, but it allows you to upload files up to 500 MB.

Releasing

Make sure to include a changeset in your PR. You can do this by running:

pnpm changeset
git commit -am "changeset"
git push

Once such a commit gets merged in main, then GitHub will open a versioning PR you can merge. And the package will be automatically published to npm.

A note for Vite users

@vercel/blob reads the token from the environment variables on process.env. In general, process.env is automatically populated from your .env file during development, which is created when you run vc env pull. However, Vite does not expose the .env variables on process.env.

You can fix this in one of following two ways:

  1. You can populate process.env yourself using something like dotenv-expand:
pnpm install --save-dev dotenv dotenv-expand
// vite.config.js
import dotenvExpand from 'dotenv-expand';
import { loadEnv, defineConfig } from 'vite';

export default defineConfig(({ mode }) => {
  // This check is important!
  if (mode === 'development') {
    const env = loadEnv(mode, process.cwd(), '');
    dotenvExpand.expand({ parsed: env });
  }

  return {
    ...
  };
});
  1. You can provide the credentials explicitly, instead of relying on a zero-config setup. For example, this is how you could create a client in SvelteKit, which makes private environment variables available via $env/static/private:
import { put } from '@vercel/blob';
+ import { BLOB_TOKEN } from '$env/static/private';

const blob = await head("filepath", {
-  token: '<token>',
+  token: BLOB_TOKEN,
});

Dependencies (3)

Dev Dependencies (13)

Package Sidebar

Install

npm i vercel-blob-no-undici

Weekly Downloads

0

Version

0.22.4

License

Apache-2.0

Unpacked Size

288 kB

Total Files

23

Last publish

Collaborators

  • k2on