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
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 theBufferand return the storedkeyand its publicurl.delete(key)— remove a stored object.getUrl(key)— build the public URL for a key.
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: