This is a React demo showcasing the Cloudinary Media Library Widget integration with support for multiple product environments and proper transformation handling.
- Media Library Widget: Browse and select images/videos from Cloudinary
- Multiple Product Environment Support: Configure and switch between different product environments
- Simple Configuration: Easy-to-edit configuration file for cloud environments
- Transformation-Aware: Automatically handles transformed vs original URLs
- React Integration: Built with React and TypeScript
- Modern UI: Clean, responsive design with environment switching
-
Clone the repository:
git clone https://github.com/yourusername/media-library-widget-react.git cd media-library-widget-react
-
Install dependencies:
npm install
-
Configure your Cloudinary environments (see detailed setup below)
-
Start the development server:
npm run dev
-
Open your browser to
http://localhost:5173
- Sign up: Create an account at Cloudinary
- Get credentials: Navigate to API Keys in your dashboard
- Note down: Your
cloud_name
andapi_key
(you don't need the API secret for this widget)
Edit src/config/clouds.ts
and replace the placeholder values with your actual Cloudinary credentials:
export const cloudConfigs: CloudConfig[] = [
{
name: "Production",
cloudName: "mycompany123",
apiKey: "123456789012345"
},
{
name: "Staging",
cloudName: "mycompany456",
apiKey: "987654321098765"
},
{
name: "Development",
cloudName: "mycompany789",
apiKey: "111222333444555"
}
// Add more environments as needed...
];
Important:
- Only product environments with real credentials (no placeholders) will appear in the dropdown
- You can add as many product environments as you need
- Each product environment can have a different name, cloud name, and API key
- Start the app:
npm run dev
- Check the dropdown: You should see your configured environments
- Select a product environment: The Media Library Widget should initialize
- Test the widget: Click "Open Media Library" to verify it works
- Configuration Check: The app loads cloud configurations from
src/config/clouds.ts
- Environment Filtering: Only product environments with real credentials are displayed
- Widget Initialization: Media Library Widget initializes with the selected environment
- Environment Switching: Users can switch between different product environments via dropdown
- Asset Handling: Automatically uses transformed URLs (
asset.derived
) when available
- Unlimited environments: Add as many as you need in the config file
- Easy switching: Dropdown allows users to switch between environments
- Automatic filtering: Placeholder configurations are automatically hidden
- Real-time updates: Widget reinitializes when switching environments
The widget automatically detects and uses the correct URLs:
- With transformations: Uses
asset.derived
(transformed URL) - Without transformations: Falls back to
asset.secure_url
(original URL)
This prevents the common integration issue of storing wrong URLs when transformations are applied.
interface CloudConfig {
name: string; // Display name (e.g., "Production", "Staging")
cloudName: string; // Cloudinary cloud name
apiKey: string; // Cloudinary API key
}
Modify the widget settings in src/components/MediaLibraryWidget.tsx
:
max_files
: Number of files that can be selecteddefault_transformations
: Default image transformations appliedintegration
: Custom integration details for analytics
- CSS: Edit
src/App.css
for custom styling - Layout: Modify
src/components/MediaLibraryWidget.tsx
for UI changes - Themes: Add CSS variables for easy theming
"No environments configured" message:
- Check that
src/config/clouds.ts
has real credentials (no placeholders) - Ensure all three fields (name, cloudName, apiKey) are filled in
- Restart the development server after making changes
Widget not initializing:
- Verify your Cloudinary credentials are correct
- Check browser console for error messages
- Ensure your cloud name and API key match exactly
Environment not appearing in dropdown:
- Make sure the configuration doesn't contain placeholder text like "your_cloud_name_1"
- Check that all required fields are populated
- Restart the server after configuration changes
- Hot reload: Most changes will automatically reload in the browser
- Console logging: Check browser console for detailed widget initialization logs
- Environment switching: Test switching between different environments to ensure all work
- React 19 - Modern React with hooks and functional components
- TypeScript - Type-safe development experience
- Vite - Fast build tool and development server
- Cloudinary Media Library Widget - Official Cloudinary widget for media selection
- Fork the repository
- Create a feature branch:
git checkout -b feature/amazing-feature
- Commit your changes:
git commit -m 'Add amazing feature'
- Push to the branch:
git push origin feature/amazing-feature
- Open a Pull Request
This project is open source and available under the MIT License.