Storage

Custom Adapter

Create your own custom storage adapter for VitNode.

Want to store files somewhere else? Implement the StorageApiPlugin interface. An adapter is a plain factory returning three methods — upload, delete and getUrl — plus an optional static descriptor for disk-backed adapters that serve files through Hono's serveStatic.

Usage

Create the adapter

src/utils/storage/my-storage.ts
import type { StorageApiPlugin } from "@vitnode/core/api/models/storage";

export const MyStorageAdapter = ({
  bucket = "",
}: {
  bucket: string | undefined;
}): StorageApiPlugin => {};

Implement the methods

  • upload({ key, body, contentType }) — persist the Buffer and return the stored key and its public url.
  • delete(key) — remove a stored object.
  • getUrl(key) — build the public URL for a key.
src/utils/storage/my-storage.ts
import type {
  StorageApiPlugin,
  StorageUploadArgs,
} from "@vitnode/core/api/models/storage";

export const MyStorageAdapter = ({
  bucket = "",
}: {
  bucket: string | undefined;
}): StorageApiPlugin => {
  const getUrl = (key: string) => `https://cdn.example.com/${bucket}/${key}`;

  return {
    getUrl,
    upload: async ({ key, body, contentType }: StorageUploadArgs) => {
      // ...persist `body` under `key`
      return { key, url: getUrl(key) };
    },
    delete: async (key: string) => {
      // ...remove `key`
    },
  };
};

Keys are pre-built for you

The framework builds the month_{month}_{year}/{folder}/<uuid>.<ext> key before calling upload, so an adapter just stores the body at the given key — no path logic needed.

Publish to NPM

If you want to share your adapter, publish it as an NPM package. Reference implementations:

On this page