Download your media files from Payload Cloud's S3 storage to a local directory.
The script runs inside your Payload project using the local API to:
- Discover all upload-enabled collections from your Payload config
- Query each collection to get every document's filename (including image resize variants)
- Authenticate with Cognito via
@payloadcms/payload-cloud'sgetStorageClient - Download each file from S3 to a local
export-uploads/directory
-
Copy
src/export-uploads.tsinto your Payload project'ssrc/directory -
Update the config import path to match your project:
const { default: config } = await import('./payload.config.js') // adjust to your config location
-
Add the following environment variables to your
.env:From the File Storage tab on your Payload Cloud dashboard, use copy button on far right:
PAYLOAD_CLOUD=true PAYLOAD_CLOUD_ENVIRONMENT=prod PAYLOAD_CLOUD_PROJECT_ID= PAYLOAD_CLOUD_COGNITO_USER_POOL_ID= PAYLOAD_CLOUD_COGNITO_USER_POOL_CLIENT_ID= PAYLOAD_CLOUD_COGNITO_IDENTITY_POOL_ID= PAYLOAD_CLOUD_BUCKET= PAYLOAD_CLOUD_BUCKET_REGION= PAYLOAD_CLOUD_COGNITO_PASSWORD= # from the 'Cognito Password' fieldFrom Settings → Environment Variables:
PAYLOAD_SECRET= # from 'Payload Secret'From the Database tab:
DATABASE_URI= # your MongoDB connection stringNote: If
PAYLOAD_CLOUD_COGNITO_PASSWORDcontains a$character, escape it as\$in your.envfile to prevent variable interpolation. -
Install
tsxas a dev dependency if not already installed:npm install -D tsx
-
Add the following scripts to your
package.json:{ "scripts": { "export-uploads": "tsx src/export-uploads.ts", "export-uploads:apply": "tsx src/export-uploads.ts --apply" } }
Dry run (default) — lists all files without downloading:
npm run export-uploadsDownload — downloads files to ./export-uploads/:
npm run export-uploads:applyThe script is resume-friendly: files that already exist locally are skipped.
Files are organized by collection:
./export-uploads/
media/
image1.jpg
image1-640x480.jpg # image resize variant
image2.png
documents/
report.pdf