Allow users to organize uploads by specifying folder paths during upload.
Dynamic folders let users choose where files are stored in Cloudinary by entering a folder path in the upload form. This feature also includes smart asset moving - when you change the folder path, the plugin moves the existing asset in Cloudinary instead of creating a duplicate.
cloudinaryStorage({
collections: {
media: {
folder: {
path: 'uploads', // Default folder
enableDynamic: true, // Enable folder input
},
},
},
})collections: {
media: {
folder: {
path: 'uploads',
enableDynamic: true,
fieldName: 'customFolderField', // Use custom field name
},
},
}Allow users to type the folder path when uploading:
cloudinaryStorage({
collections: {
media: {
folder: {
path: 'uploads', // Default folder
enableDynamic: true, // Enable folder input
fieldName: 'cloudinaryFolder', // Field name (optional, defaults to 'cloudinaryFolder')
},
},
},
})This adds a "Cloudinary Folder" text field to the upload form where users can specify folder paths like:
products/electronicsblog/2024/julyteam/marketing
When you change the folder path for an existing file, the plugin:
- Uses Cloudinary's rename API to move the asset
- Preserves the same public ID and version
- Updates the folder location without re-uploading
- Maintains all existing URLs and transformations
If you need more control over the folder field (e.g., custom UI component, validation, or dropdown selector), you can prevent the plugin from creating the field automatically:
cloudinaryStorage({
collections: {
media: {
folder: {
path: 'uploads',
enableDynamic: true,
fieldName: 'cloudinaryFolder',
skipFieldCreation: true, // Prevent automatic field creation
},
},
},
})Then add your own field to the collection:
const Media: CollectionConfig = {
slug: 'media',
upload: {
disableLocalStorage: true,
},
fields: [
{
name: 'cloudinaryFolder',
type: 'text',
label: 'Upload Folder',
defaultValue: 'uploads',
admin: {
description: 'Choose the folder for this upload (e.g., products/2024)',
placeholder: 'uploads',
},
// Add validation if needed
validate: (value) => {
if (value && !value.match(/^[a-zA-Z0-9\/_-]+$/)) {
return 'Folder name can only contain letters, numbers, hyphens, underscores, and slashes'
}
return true
},
},
// ... other fields
],
}The plugin will still use the field value during upload, but you have complete control over the field's behavior and appearance.
Create date-based organization by using the folder input to specify dates:
uploads/2024/07/
uploads/2024/08/
uploads/2025/01/
Organize by the type of content:
images/products/
images/blog/
videos/tutorials/
documents/contracts/
For user-based organization:
users/john-doe/
users/jane-smith/
teams/marketing/
teams/development/
- Consistent Structure: Use a consistent folder naming convention
- Avoid Special Characters: Stick to alphanumeric characters, hyphens, and underscores
- Limit Depth: Don't create overly deep folder structures (max 3-4 levels)
- Consider Performance: Cloudinary performs better with a balanced folder structure
- Plan Ahead: Design your folder structure before uploading many files
- Use Smart Moving: Change folder paths instead of re-uploading files to new locations
# By content type
media/
├── images/
│ ├── products/
│ ├── blog/
│ └── users/
├── videos/
│ ├── tutorials/
│ └── marketing/
└── documents/
# By date
uploads/
├── 2024/
│ ├── 01-january/
│ ├── 02-february/
│ └── ...
└── 2025/
# By project/client
clients/
├── acme-corp/
│ ├── assets/
│ └── documents/
└── xyz-inc/
├── branding/
└── products/
# Hybrid approach
content/
├── 2024/
│ ├── products/
│ ├── blog/
│ └── marketing/
└── 2025/
├── products/
└── blog/
- Folders are automatically created in Cloudinary when files are uploaded
- No need to pre-create folders in the Cloudinary dashboard
- The plugin handles folder creation seamlessly
- Uses Cloudinary's
renameAPI to move assets between folders - Preserves the same public ID and version
- All existing URLs continue to work
- Transformation URLs are automatically updated
- Folder names are cleaned to remove invalid characters
- Leading and trailing slashes are automatically removed
- Empty folder names default to the configured default folder
When using dynamic folders, ensure your Cloudinary API credentials have permission to create and upload to the specified folders. You can manage folder permissions in your Cloudinary dashboard under Settings > Security.