AI Resource Pro / website / docs / cloudflare-images-migration.md
Cloudflare Images Migration
This document outlines the migration from local image storage to Cloudflare Images for the AI Resource Pro website.
Overview
Previously, the website stored all uploaded images in the /public/images/ directory with categorized subdirectories. Now, all images are stored in Cloudflare Images, which provides the following benefits:
- Global CDN for faster image loading
- Automatic image optimization and responsive sizing
- Reduced storage requirements on the server
- Better security and access control
Configuration
To use Cloudflare Images, you need to set up the following environment variables:
CLOUDFLARE_ACCOUNT_ID: Your Cloudflare account IDCLOUDFLARE_IMAGE_API_KEY: Your Cloudflare Images API key (with Images Write permission)
You can get these values from your Cloudflare dashboard.
Image Categories
The same image categories are maintained in the new system:
blog: Images used in blog postsnews: Images used in news articlestools: Images related to toolslearning: Images used in learning resourcesmisc: Miscellaneous imagesmidjourney: AI-generated images
Instead of storing these as directory paths, they are now stored as metadata in Cloudflare Images.
API Changes
The API endpoints have been updated to work with Cloudflare Images:
POST /api/upload-image: Uploads an image to Cloudflare ImagesGET /api/upload-image?category=...: Lists images, optionally filtered by categoryDELETE /api/upload-image?imageId=...: Deletes an image by its IDPATCH /api/upload-image: Updates an image's metadata (e.g., changes category)
Image URLs
Image URLs now come directly from Cloudflare's CDN instead of the local /images/ path. They will look like:
https://imagedelivery.net/<ACCOUNT_HASH>/<IMAGE_ID>/<VARIANT>
Migration Process
To migrate existing images:
- Set up Cloudflare Images in your Cloudflare account
- Create the necessary variants for your images
- Upload all existing images from
/public/images/to Cloudflare Images with their categories as metadata - Update the database with the new image URLs
Local Development
Local development works the same way - the API calls to Cloudflare Images will work as long as the environment variables are properly configured.
Troubleshooting
If images are not appearing:
- Check that the Cloudflare Images API credentials are correct
- Verify that the image variants are set up properly in Cloudflare
- Check browser console for any CORS or loading errors
- Ensure the image IDs referenced in the application match those in Cloudflare Images