klnap

payload storage sanity

by klnap
Cloud storage
v3
>=3.94.1 <4
MIT

Overview

Summary generated from the README

Stores Payload upload collection files in Sanity Content Lake while Payload keeps media records, access control, relationships, drafts and versions. It is added as a plugin and enabled per upload collection with Sanity project credentials. Automatic asset cleanup requires the PostgreSQL adapter, and the Sanity write token must stay on the server. Requires Payload 3.94.1 or later below 4.

Features

  • Sanity-backed upload collections with native asset snapshots
  • Image, video, audio and generic file asset support
  • Editor-applied crops, focal points and video posters
  • Reference-aware post-commit asset cleanup coordinated through PostgreSQL
  • Optional Cloudflare Worker upload transport
  • Next.js image and video components plus framework-neutral URL helpers

Use cases

  • Serve Payload media from the Sanity CDN instead of local disk or an object store
  • Manage crops and focal points on images used in a Next.js frontend
  • Clean up unreferenced Sanity assets automatically when media documents are deleted

From the author

Sanity-powered storage for Payload CMS with an enhanced media admin UI.

Installation

npm i @klnap/payload-storage-sanity

0

Stars

0

Forks

0

Open Issues

3 days ago

Last Updated

1.2k

Weekly Downloads

v0.5.0

npm Version

1.2 MB

Unpacked Size

8

Dependencies

GitHub stars

00 since Nov 22

Show data
GitHub stars by day (UTC)
DateStars
Dec 6, 20260
Dec 5, 20260
Dec 4, 20260
Dec 3, 20260
Dec 2, 20260
Dec 1, 20260
Nov 30, 20260
Nov 29, 20260
Nov 28, 20260
Nov 27, 20260
Nov 26, 20260
Nov 25, 20260
Nov 24, 20260
Nov 23, 20260
Nov 22, 20260
npm weekly downloads

1.4K+1.4K since Sep 18

Show data
npm weekly downloads by day (UTC)
DateWeekly downloads
Dec 6, 20261,447
Dec 5, 20261,455
Dec 4, 20262,116
Dec 3, 20261,898
Dec 2, 20261,863
Dec 1, 20261,791
Nov 30, 20261,233
Nov 29, 2026904
Nov 28, 2026706
Nov 27, 20260
Nov 26, 20260
Nov 25, 20260
Nov 24, 20260
Nov 23, 20260
Nov 22, 20260
Nov 21, 20260
Nov 20, 20260
Nov 19, 20260
Nov 18, 20260
Nov 17, 20260
Nov 16, 20260
Nov 15, 20260
Nov 14, 20260
Nov 13, 20260
Nov 12, 20260
Nov 11, 20260
Nov 10, 20260
Nov 9, 20260
Nov 8, 20260
Nov 7, 20260
Nov 6, 20260
Nov 5, 20260
Nov 4, 20260
Nov 3, 20260
Nov 2, 20260
Nov 1, 20260
Oct 31, 20260
Oct 30, 20260
Oct 29, 20260
Oct 28, 20260
Oct 27, 20260
Oct 26, 20260
Oct 25, 20260
Oct 24, 20269
Oct 23, 20269
Oct 22, 20269
Oct 21, 20269
Oct 20, 20269
Oct 19, 20269
Oct 18, 20269
Oct 17, 20260
Oct 16, 20260
Oct 15, 2026200
Oct 14, 2026200
Oct 13, 2026200
Oct 12, 2026200
Oct 11, 2026200
Oct 10, 2026200
Oct 9, 2026200
Oct 8, 20260
Oct 7, 20260
Oct 6, 20260
Oct 5, 20260
Oct 4, 20260
Oct 3, 20260
Oct 2, 20260
Oct 1, 20260
Sep 30, 20260
Sep 29, 20260
Sep 28, 20260
Sep 27, 20260
Sep 26, 20260
Sep 25, 20260
Sep 24, 20264
Sep 23, 20264
Sep 22, 20264
Sep 21, 20264
Sep 20, 20264
Sep 19, 20264
Sep 18, 20264

Each point is npm's rolling 7-day download count.

Health Score

72/100Good

Composite score based on GitHub activity, stars, npm downloads, publish recency, dependency count, and package size.

Badge for your README

Payload Directory health badge
Markdown
[![Payload Directory](https://payloaddirectory.dev/badge/1471027626-root.svg)](https://payloaddirectory.dev/plugins/1471027626-root)
HTML
<a href="https://payloaddirectory.dev/plugins/1471027626-root"><img src="https://payloaddirectory.dev/badge/1471027626-root.svg" alt="Payload Directory"></a>
Updated Dec 3, 2026Created Nov 25, 2026Published Dec 3, 2026

README

@klnap/payload-storage-sanity

Store Payload media files in Sanity Content Lake. Payload remains the source of media records, access control, relationships, drafts and versions; Sanity stores and serves the asset bytes.

Features

  • Sanity-backed Payload upload collections with native asset snapshots.
  • Image and video asset management, plus audio and generic files.
  • Native media metadata, editor-applied crops, focal points and video posters.
  • Reference-aware, post-commit asset cleanup coordinated through PostgreSQL.
  • Optional Cloudflare Worker upload transport.
  • Framework-neutral asset utilities and optional Next.js media consumers.

Install

bun add @klnap/payload-storage-sanity
# or
npm install @klnap/payload-storage-sanity

Requirements: Node.js ^22.23.5, ^24.22.3 or >=26.13.1; Payload and its UI/translation packages >=3.94.1 <4; React and React DOM ^19.3.1; and @sanity/client >=6 <9.

Automatic cleanup requires Payload's PostgreSQL adapter. deleteSanityAssets defaults to true; use a dedicated dataset and coordinate writers through this plugin. Set deleteSanityAssets: false when asset ownership is shared or uncertain. Keep the Sanity write token on the server.

import { sanityStorage } from '@klnap/payload-storage-sanity'

sanityStorage({
  projectId: process.env.SANITY_PROJECT_ID!,
  dataset: process.env.SANITY_DATASET!,
  token: process.env.SANITY_API_TOKEN!,
  collections: { media: true },
})

Add the plugin to an existing Payload configuration and upload collection. Configure @payloadcms/db-postgres in the host app when automatic cleanup is enabled. See operations before enabling deletion or upgrading an existing schema.

Frontend

The framework-neutral @klnap/payload-storage-sanity/consumers entry exports asset types and URL helpers. The optional @klnap/payload-storage-sanity/consumers/next entry provides SanityImage, SanityVideo and SanityImageOrVideo. Image consumers need Next.js >=16.4.5 <17. Video consumers also need next-video >=2.8 <3 and player.style >=0.3 <1; storage-only and image-only consumers do not need those video peers.

import { SanityImage, SanityVideo, SanityImageOrVideo } from '@klnap/payload-storage-sanity/consumers/next'

<SanityImage asset={image} sizes="100vw" />
<SanityVideo asset={video} preload="none" controls />
<SanityImageOrVideo asset={media} fill sizes="(max-width: 768px) 100vw, 33vw" video={{ mode: 'background' }} />

See frontend usage for responsive images, poster configuration, crop and focal positioning, and loading behavior.

Asset lifecycle and security

Sanity and PostgreSQL do not share an atomic transaction. Cleanup is recorded in the Payload transaction and runs after commit. Unknown remote deletion outcomes fail closed until an operator has positive evidence to resolve the exact outbox record; see the recovery procedure.

Sanity CDN URLs are publicly fetchable by anyone who knows them, including URLs from private datasets. Payload access rules do not make a direct CDN URL private. Standard Sanity video assets are files, not adaptive streams; playback depends on browser codec support.

Performance and compatibility

Images use Next.js responsive selection with Sanity CDN transformations. Video preload and poster loading are independent. See the measured frontend observations; laboratory results are not field Web Vitals or universal guarantees.

This package is ESM. Browser-side media preparation is an Admin convenience, not a server-side validation boundary. See the security policy, changelog and MIT license.

Similar plugins