stream block passed to bunnyStorage(...).
payload.config.ts
mp4Fallback: true or signed URLs with redirect — otherwise the plugin throws at startup. See Access control and mp4Fallback. Set disablePayloadAccessControl: true on the collection to serve straight from the CDN instead, where this requirement doesn’t apply.
Files whose MIME type matches mimeTypes are routed to Bunny Stream. Everything else goes to Bunny Storage, if configured. When a document gets a new file that goes to Bunny Storage, the plugin removes its Stream video ID. The old video then follows the rules in Replaced videos and versions. The plugin names a new video in Bunny after the uploaded file name, without Payload’s -original suffix. The file URL and the admin thumbnail come from Bunny Stream when the document has a Stream video ID and its file is a video or audio file, matches mimeTypes or has no MIME type. Other files get the Bunny Storage URL. Video metadata for each document lives in the bunnyData field.
Options
Default
mimeTypes cover the common video and audio formats: MP4, MKV, WebM, FLV, AVI, MOV, WMV, MPEG, TS, MXF, and MP3/OGG/WAV audio.
The top-level
stream block is optional. If every collection points at its own stream library, you can omit the global stream entirely.Access control and MP4 fallback
By default, files are served through Payload’s access control (disablePayloadAccessControl isn’t set on the collection). For Stream videos in this mode, Bunny can’t serve HLS directly through Payload’s proxy, so you need one of:
mp4Fallback: true— Payload proxies the MP4 rendition instead of HLS. When the storedresolutionsare missing or wrong, the first request stores the rendition it found. Like the status writes, this goes straight to the database: it does not run your collection hooks, does not create a version and does not changeupdatedAt.- Signed URLs with redirect — set
signedUrls.staticHandler.redirect: true(globally or on the collection) so Payload redirects straight to Bunny’s HLS stream instead of proxying it. This is the faster option — see Signed URLs.
mp4Fallback, the redirect is the only way to serve the video. If shouldUseSignedUrl returns false for a file, there is no redirect, and the file route answers 400.
When Payload proxies the MP4 fallback or a Stream thumbnail, it fetches the file from Bunny server-side. If your Stream library uses a BlockNoneReferrer rule, set referer to a value the library allows so those requests aren’t rejected. Default libraries need nothing here.
Edit view player
The edit view of a Stream video or audio file shows the Bunny Stream player instead of Payload’s built-in player, also with TUS uploads. WithdisablePayloadAccessControl: true, Payload’s own player gets the HLS playlist (playlist.m3u8) as the file URL and cannot play it outside Safari. With Payload access control on and mp4Fallback, it gets the MP4 file. While Bunny encodes the file, the preview shows a processing message and switches to the player when the file is ready. With status: false the player shows right away. Files without a Bunny Stream video ID and other file types keep Payload’s own preview.
The plugin adds the player to the collection’s upload.admin.components.filePreview for video/* and audio/*, but only for a category that has a type in the Stream mimeTypes. With mimeTypes: ['video/mp4'], it adds only video/*:
- A
filePreviewcomponent, or a map with*, stays as it is. With*the map covers every file type, so the plugin adds nothing. - In any other map, a
video/*oraudio/*entry that is already there stays, and the plugin adds the missing ones.
plugins before the adapters in storage, whatever the order of the plugins array. So the media preview plugin always sets its map first. The map has *, so this plugin adds nothing to it. With the media preview plugin, register the Bunny Stream adapter (bunnyStreamAdapter) in its adapters, and the adapter shows the player. Without the adapter, the media preview plugin sets video/* and audio/* to false, and Stream files get Payload’s own player, which cannot play the HLS playlist outside Safari. The plugin logs a warning at startup when a Stream collection with preview on sets video/*, audio/* or one of its Stream mimeTypes, for example video/mp4, to false.
Set preview: false to turn the player off, globally or for one collection. The player is in the import map, so run payload generate:importmap after you upgrade.
Replaced videos and versions
Stream videos follow the same rule as files in Bunny Storage:- With
versions(the Payload 4 default), a replaced video stays in your Stream library while any document or version references it. So restoring a version brings back a working video. The video is deleted when no document and no version references it any more, in any collection that uses the same library. This includes versions that Payload removes because ofmaxPerDoc, and an autosave version that a new video replaces. Payload overwrites the autosave version of a draft in place, so the old video loses that reference on the next autosave. - With
versions: false, the old video is deleted when you replace it, as before. Setversions: falseon the collection to get this behavior back.
payload.db.*, do not delete videos.
Renaming a file (payload.renameFile, or the rename operation in REST and GraphQL) and restoring a version copy nothing in Stream. The old and the new key point to the same video.
Cleanup
Some uploads leave videos in your library that no document uses. This happens when an upload stops halfway, for example after a closed tab or a failed TUS session. It also happens when the upload finishes but the document is never saved, for example when a bulk upload save fails. Enablecleanup to remove these videos on a schedule.
Cleanup only checks uploads that this plugin started. Before it deletes a fully uploaded video, it makes sure no document references it. It never touches videos that other services or the Bunny dashboard add to the same library. Keep maxAge longer than an editor might leave an upload unsaved, because a document saved after cleanup has run points to a deleted video.
Cleanup registers a Payload job task. Something must run it: the Payload jobs runner, a cron call to the plugin’s tasks endpoint, the
bunny:task CLI or your own code. See Background tasks.
There is one cleanup task for the whole plugin, and its
schedule is global-only — set it on the top-level stream.cleanup. When a collection points at its own library, its cleanup controls only maxAge (each library’s stale sessions are swept with that library’s own cutoff); it can’t set a separate schedule.Collection overrides
A collection’sstream can be one of three things:
- a partial override (
mimeTypes,mp4Fallback,preview,status,thumbnailTime,tus,uploadTimeout) — merged onto the global library; - full options (with their own
apiKey/hostname/libraryId) — this collection uses its OWN stream library, ignoring the global library entirely; false— disable Bunny Stream for this collection.
apiKey. Full options inherit nothing from the global library — mimeTypes, mp4Fallback, tus, and the rest fall back to plugin defaults, not the global library’s values. Provide that library’s own tokenSecurityKey for signed URLs, and its own webhook.secret if you use webhooks. Per-collection cleanup carries only maxAge, and per-collection status.sync carries only limit and maxAge. Both schedules are global-only. With full options, status.link is true and status sync is off unless you set them.
A partial tus: true or tus: { … } turns TUS on for that collection, even when the global stream.tus is off. tus: false turns it off.
A partial preview turns the edit view player on or off for that collection.
See Collection overrides for the full-options vs partial-override rules and the complete list of options.