Adds an afterRead hook to a chosen upload collection that checks whether each file and its size variants exist locally. Missing files are downloaded from a configured origin URL and written to the upload directory. It is intended for development and can be disabled in production. Requires Payload 3.17.1 or later.
Plugin to getting production files on a development server on demand.
Installation
npm i payload-files-proxy1
Stars
0
Forks
0
Open Issues
7 months ago
Last Updated
0
Weekly Downloads
v1.0.8
npm Version
10.8 KB
Unpacked Size
0
Dependencies
Trends appear after 7 days of data. Daily snapshots have not started yet.
Trends appear after 7 days of data. Daily snapshots have not started yet.
Each point is npm's rolling 7-day download count.
Health Score
Composite score based on GitHub activity, stars, npm downloads, publish recency, dependency count, and package size.
Badge for your README
[](https://payloaddirectory.dev/plugins/938831442-root)<a href="https://payloaddirectory.dev/plugins/938831442-root"><img src="https://payloaddirectory.dev/badge/938831442-root.svg" alt="Payload Directory"></a>README
Small Payload CMS plugin to fetch missing media files from an origin site during local development, inspired by Drupal's stage_file_proxy approach.
Use this when you do not want to sync a large uploads folder locally but still need media files to appear in pages and the admin UI.
npm install payload-files-proxy
# or
pnpm add payload-files-proxy
# or
yarn add payload-files-proxy
import path from 'path'
import { buildConfig } from 'payload'
import { payloadFilesProxy } from 'payload-files-proxy'
export default buildConfig({
collections: [
{
slug: 'media',
upload: {
staticDir: path.resolve('./uploads'),
},
},
],
plugins: [
payloadFilesProxy({
mediaCollectionSlug: 'media',
mediaDirectory: path.resolve('./uploads'),
originUrl: 'https://your-production-site.com',
disabled: process.env.NODE_ENV === 'production',
}),
],
})
payloadFilesProxy receives:
mediaCollectionSlug?: string
config.collections.mediaDirectory: string (required by type)
collection.upload.staticDir is truthy, that value is used instead.${mediaDirectory}/${mediaCollectionSlug}.originUrl: string
originUrl + doc.url.disabled?: boolean
true, plugin is a no-op and config is returned unchanged.Based on the current source (src/index.ts and src/utils.ts):
disabled !== true.mediaCollectionSlug.uploadDir from collection.upload.staticDir or fallback ${mediaDirectory}/${mediaCollectionSlug}.mediaCollection.hooks to include an afterRead hook list composed of:
afterRead hooks (if any)checkIfFileExists(uploadDir, originUrl)doc.url is missing, it returns immediatelydoc.sizes variants (if present)fs.statfetch(originUrl + file.url) and writes bytes with fs.writeFileresponse.ok before writing.fetch only), so authenticated origins are not supported out of the box.@TODO) indicating uploadDir resolution may be incorrect in some setups.mediaCollection.hooks is reassigned and keeps previous afterRead, but other hook groups are not preserved.disabled: true or NODE_ENV guard).url and filenamemediaCollectionSlug matches your collection slugoriginUrl + doc.url is reachabledoc.sizes[*].url and doc.sizes[*].filename existPRs are welcome. If behavior changes, document migration notes clearly in the README.
MIT
Inspired by Drupal's stage_file_proxy module and similar on-demand media proxy patterns.
Topics
mux video
Upload and manage Mux videos from the Payload admin with public or signed playback
872.7k/wk83v3
image search
Search and import images from Unsplash, Pexels and Pixabay without leaving the Payload admin
78533/wk114v3
payload plugin aspect preview
Crop and focal point editing with live multi-aspect-ratio previews for Payload upload collections
7534/wk6v3
payload plugin media preview
Preview images, video, audio, code, CSV and Office files in the Payload admin list and edit views
7294/wk13v4
blur data urls
Generates blur placeholder data URLs for images uploaded to Payload media collections
6966/wk83v3
payload media
Search Unsplash, Pexels and Pixabay stock images and videos from Payload upload collections
680/wk8v4