Dev48
Language
  • About
  • Services
  • Industries
  • Technologies
  • Articles
  • Contacts
Book a call
    Home/Articles/Prevent expired media from publishing with strapi nextjs and cloudinary
Dev48
info@dev48.org+375 29 320-40-96WhatsApp@isky_by

© 2026 · All rights reserved.

Prevent Expired Media From Publishing With Strapi, Next.js, and Cloudinary

Source: Cloudinary Blog•December 3, 2026 at 03:19 PM

Prevent Expired Media From Publishing With Strapi, Next.js, and Cloudinary

The post Prevent Expired Media From Publishing With Strapi, Next.js, and Cloudinary appeared first on Cloudinary Blog .

A headless CMS can stop expired licensed media from publishing by intercepting the server-side publish operation, reading the asset’s current rights metadata from Cloudinary, and continuing only when every license, territory, release, and approval rule passes. The same gate should also apply a delivery access window so an image that’s valid today doesn’t remain public after its license expires.

This tutorial builds that control with Strapi 5, Next.js, Cloudinary structured metadata, the Cloudinary Admin API, and time-limited media access.

  • Live demo: https://cloudinary-media-rights-gate.vercel.app/
  • GitHub repo: https://github.com/musebe/Prevent-Expired-Media-From-Publishing-With-Strapi–Next.js–and-Cloudinary
  • Documentation: https://cloudinary-media-rights-gate.vercel.app/docs

The result is a technical governance layer, but your policy still needs to reflect the contracts, markets, release requirements, and approval process used by your organization.

The project makes Cloudinary the source of truth for media rights and puts a fail-closed decision directly in Strapi’s publish path:

A small Next.js application exposes the same policy as an interactive demo. It also loads four reusable Strapi drafts backed by real Cloudinary assets: active, expired, region-restricted, and approval-pending.

An image can be technically valid and still be unusable for a specific publication. Its license may not have started, may have expired, may exclude the target market, or may require an approval that’s still pending.

Storing a Cloudinary URL in the CMS does not answer those questions. Copying a license date into the article record is also fragile because the CMS copy can drift from the asset’s current rights record.

The gate in this tutorial uses two complementary controls:

Cloudinary documents structured metadata as typed, programmable fields attached to assets. Its digital-rights guidance also describes asset expiration and scheduled access as rights-management controls. See Cloudinary structured metadata and Cloudinary digital rights management.

You’ll need:

  • Node.js 22 through 24. This repository recommends Node.js 24.
  • npm.
  • A Cloudinary account and product environment.
  • A local Strapi administrator account, created the first time the CMS starts.

The project uses Strapi 5 with Draft & Publish, Next.js 16, React 19, the official Strapi Cloudinary upload provider, the Cloudinary Node.js SDK, and Vitest.

Cloudinary access control is available across Cloudinary accounts, but token-authenticated delivery outside a public access window requires a qualifying plan and account configuration. The public license window used by this tutorial does not require the browser to receive an API secret. Review the current Cloudinary media access-control requirements for your product environment.

Clone the finished application and install its workspaces:

Create the local Strapi environment file:

Run the random-value command for every Strapi secret. Then add your Cloudinary credentials to cms/.env:

Keep the API secret on the server. Do not prefix it with NEXT_PUBLIC_, expose it to a Client Component, or commit cms/.env.

The complete local configuration is documented in the repository’s environment template.

The policy needs stable field identifiers that code and asset managers can share. This project defines seven Cloudinary structured metadata fields:

The shared schema keeps these IDs in one package:

Read the complete rights metadata schema. It also declares controlled region and approval values so typos cannot silently create new policy states.

Cloudinary supports typed fields, list data sources, validation, defaults, and mandatory values. This tutorial leaves the fields non-mandatory at the Cloudinary schema level because the fail-closed policy demonstrates how missing evidence is handled. In a production workflow, making high-confidence fields mandatory can improve data quality before an asset reaches the CMS.

Run the idempotent setup command once for the Cloudinary product environment:

The setup script reads existing field definitions and creates only the missing ones:

See the complete Cloudinary provisioning script.

To verify the result, open Settings in the Cloudinary Console, choose Manage Structured Metadata, and confirm that all seven drm_* fields exist. Asset editors can then populate the fields from an asset’s metadata panel or through an authenticated API workflow.

Strapi’s media record needs a Cloudinary locator, but Cloudinary remains authoritative for rights evidence. Configure the official upload provider in cms/config/plugins.ts:

The full provider configuration also places uploads in a dedicated folder, adds rights-managed tags, and denies executable file types. Strapi documents provider configuration in its Media Library provider guide.

The governed Strapi collection type enables Draft & Publish and requires two policy inputs:

  • targetRegion: the market in which the article will appear.
  • hero: one Cloudinary-backed image to evaluate.

See the complete Strapi article schema. Strapi’s Draft & Publish documentation explains how a collection type keeps editable drafts separate from published documents.

The policy is a pure TypeScript function, independent of Strapi and Cloudinary network calls. That separation makes every decision branch deterministic and testable.

The expiration date is inclusive. For example, a license ending on 2026-08-30 may pass throughout that UTC calendar date. Its delivery window ends at 2026-08-31T00:00:00.000Z.

The final decision stays intentionally small:

The engine blocks missing ownership or license references, invalid dates, future or expired windows, missing or excluded regions, uncleared model releases, and unapproved creative. Read the complete rights policy and its policy tests.

An explainable result is useful to both editors and auditors. Each reason contains a stable code, a human-readable message, and the Cloudinary field that must be corrected.

When an editor selects Publish, the server must not trust rights values from the browser or a stale copy stored in Strapi. It reads the selected asset through the Cloudinary Admin API with metadata: true:

The Strapi provider supplies the Cloudinary public ID and resource type. The readback returns Cloudinary’s immutable asset_id, which the gate keeps in its audit result.

See the complete Cloudinary asset service. The Cloudinary Admin API is rate-limited, so a larger editorial system should monitor quota, cache only where the rights freshness requirement permits it, and retain the fail-closed behavior when authoritative evidence is unavailable. See the Cloudinary Admin API documentation.

Strapi 5 Document Service middleware can run before or after a Document Service action. The project registers one middleware during Strapi’s registration lifecycle and limits it to the Article content type and publish operations.

The critical control is the position of next(). It runs only after the media gate returns an allowed result and the delivery window has been applied. Any exception becomes an editor-facing Strapi ApplicationError, so a missing hero, unavailable Cloudinary record, or blocked policy never silently publishes.

Read the full publish middleware and media-rights gate. Strapi’s Document Service middleware reference documents strapi.documents.use(), the middleware context, and the requirement to return next().

A publish-time pass answers, “May this article go live now?” It does not stop a live page from referencing the same image after its license expires.

Before allowing Strapi to publish, the gate writes a Cloudinary access-control policy derived from the validated license dates:

The anonymous window keeps normal delivery public only for the licensed interval. Outside it, the token rule makes the asset restricted. Cloudinary can change this access policy without changing the asset URL.

If the access update fails, the Strapi middleware fails closed and does not call the publish operation. In a production system, also schedule unpublishing, replacement, or notification workflows so the page does not retain a broken image reference after expiry.

Start Strapi and Next.js with one command:

Wait for both processes, then open the Next.js application on port 3000 and the /admin route of the Strapi application on port 1337.

On the first run, create a local Strapi administrator. In the Next.js demo, select Load 4 CMS test drafts, open the Strapi articles, and select Publish on each draft.

You can also choose a scenario and target region in the Next.js interface, then select Run pre-publish check to inspect the evidence and policy result without changing publication state.

The proof asset connects each business rule to seeded Cloudinary evidence and a testable CMS outcome. The verified evaluation date is August 23, 2026, and the article target region is Kenya unless stated otherwise.

The repository verifies the reusable engine and CMS boundary with 19 automated tests: 10 policy tests and 9 CMS gate tests. It also seeds four Cloudinary assets with all seven drm_* fields and four matching Strapi drafts. This is a controlled proof for these policy cases, not a claim that the schema covers every licensing agreement.

Run the validation suite:

That command runs the Next.js linter, all workspace tests, the shared policy build, the Strapi build, and the Next.js production build.

For each test draft:

  • Open its hero image in Cloudinary and inspect all seven structured metadata values.
  • Open the draft in Strapi and confirm its target region and Cloudinary hero image.
  • Select Publish.
  • For a blocked case, confirm Strapi remains a draft and shows the relevant policy message.
  • For the allowed case, confirm publication succeeds and the asset’s access control reflects the license start and end.
  • Change one Cloudinary metadata value, retry publication, and confirm the new value controls the decision.

The final step proves that Strapi is not relying on a rights snapshot copied into its own record.

The demo doesn’t replace legal review. It turns an agreed rights policy into an auditable technical control and makes failure visible at the point where editors publish.

A media URL is not proof that an image is safe to publish. The publishing decision needs current, asset-level evidence and a policy that treats missing or invalid evidence as a block.

This Strapi and Cloudinary architecture creates that boundary at the real Publish button. Cloudinary structured metadata records ownership, license dates, territories, and approvals. Strapi Document Service middleware reads that evidence, the shared TypeScript policy returns explainable reasons, and Cloudinary access control limits delivery to the licensed interval.

The reusable value is the separation of responsibilities: Cloudinary owns the asset evidence, Strapi owns editorial intent, and the policy owns the decision. That makes the gate testable, auditable, and portable to other headless CMS workflows.

Intercept the CMS publish operation on the server, fetch current rights metadata from the media source of truth, evaluate it with a fail-closed policy, and continue publication only when every rule passes. Apply delivery-time expiration as a second control because a valid asset can expire after the article is published.

The license governs the asset, which may be reused by several CMS entries and channels. Keeping the authoritative record beside the asset avoids conflicting copies. Strapi retains only the Cloudinary media locator and the publication context, such as the target region.

No. Draft & Publish separates editable and live document states. The custom Document Service middleware adds the rights decision before the publish action continues.

Publication is blocked. Allowing content when the rights record cannot be verified would turn an infrastructure failure into a policy bypass.

Yes, in this implementation. An asset licensed through August 30 remains valid for that UTC calendar day. Its public delivery window ends at the start of August 31. Change this rule if your agreements define a different time boundary.

Yes. The global option satisfies every target region. Otherwise, the article’s normalized region code must appear in drm_allowed_regions.

The Cloudinary access window stops anonymous public delivery after the validated license interval. A complete editorial workflow should also identify affected documents and replace, unpublish, or review them before that date.

← All articles

What this article says

More in Media & Content

All →
Meet Muse Charm, the First Device Made Just for Your Muse
Meta

Meet Muse Charm, the First Device Made Just for Your Muse

Når krigens kaos skal gengives autentisk: Sådan skabte Dane Cody og hans team lyden til Netflix’ The Mosquito Bowl med Sennheiser
Sennheiser

Når krigens kaos skal gengives autentisk: Sådan skabte Dane Cody og hans team lyden til Netflix’ The Mosquito Bowl med Sennheiser

Spotify Wrapped 2026 introduces Audio Twins, artist trading cards, and a Time MachineПресса
Spotify

Spotify Wrapped 2026 introduces Audio Twins, artist trading cards, and a Time Machine

Building Multilingual Voice Experiences with Gemini 4 Live Translate
Agora

Building Multilingual Voice Experiences with Gemini 4 Live Translate

Automattic Acquires Miles–a WordPress Design AI Agent
Automattic

Automattic Acquires Miles–a WordPress Design AI Agent

Twitch CEO Dan Clancy is stepping down after nearly four years at the helmПресса
Twitch

Twitch CEO Dan Clancy is stepping down after nearly four years at the helm

More from Cloudinary

Get Ready for AI Shopping
Cloudinary

Get Ready for AI Shopping

How to Protect Multimodal AI Agents From Image Prompt Injection With Next.js and Cloudinary
Cloudinary

How to Protect Multimodal AI Agents From Image Prompt Injection With Next.js and Cloudinary

Five Things to Automate First When You Inherit a Third-Party Visual Media Pipeline
Cloudinary

Five Things to Automate First When You Inherit a Third-Party Visual Media Pipeline

Keep Your Products on Google: Fix Undersized Images With One Transformation
Cloudinary

Keep Your Products on Google: Fix Undersized Images With One Transformation

How to Upload Videos to Cloudinary: 4 Methods Compared
Cloudinary

How to Upload Videos to Cloudinary: 4 Methods Compared

Visual RAG for Video: Search Silent Scenes and Cite Exact Timestamps With Cloudinary
Cloudinary

Visual RAG for Video: Search Silent Scenes and Cite Exact Timestamps With Cloudinary