Branchwell

AI Resource Pro / website / docs / cloudflare-images-migration.md

Show the source

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 ID
  • CLOUDFLARE_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 posts
  • news: Images used in news articles
  • tools: Images related to tools
  • learning: Images used in learning resources
  • misc: Miscellaneous images
  • midjourney: 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 Images
  • GET /api/upload-image?category=...: Lists images, optionally filtered by category
  • DELETE /api/upload-image?imageId=...: Deletes an image by its ID
  • PATCH /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:

  1. Set up Cloudflare Images in your Cloudflare account
  2. Create the necessary variants for your images
  3. Upload all existing images from /public/images/ to Cloudflare Images with their categories as metadata
  4. 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:

  1. Check that the Cloudflare Images API credentials are correct
  2. Verify that the image variants are set up properly in Cloudflare
  3. Check browser console for any CORS or loading errors
  4. Ensure the image IDs referenced in the application match those in Cloudflare Images