Skip to main content

Overview

The system converts PNG medication images to WebP format and uploads them to Supabase Storage, then links them to the medications table.

How It Works

  1. Place PNG files in the expected directory with correct naming
  2. Run the upload script
  3. Script converts PNG to WebP (80% quality)
  4. Uploads to medication-images bucket in Supabase Storage
  5. Updates medication records with image URLs

File Naming

Files must follow this pattern:
Examples:
  • Concerta-XL-18.png → Concerta XL 18mg
  • Elvvanse-20.png → Elvvanse 20mg
  • Medikinet-XL-10.png → Medikinet XL 10mg

Setup

Environment Variables

Dependencies

Images Directory

Place PNG files in:

Running the Script

Expected Output

Database Changes

The script adds an image_url column to the medications table:

Storage Configuration

  • Bucket: medication-images (public access)
  • Format: WebP at 80% quality
  • Size limit: 1MB per file
  • MIME type: image/webp

Troubleshooting

Missing Service Role Key

Fix: Add service role key to .env file

Directory Not Found

Fix: Update IMAGES_DIR in script or move images to expected location

Medication Not Found

Fix: Check medication name in database or adjust filename

Upload Failures

Fix: Check Supabase permissions and storage quota

Manual Verification

After running the script:

Frontend Usage

Images are accessed via the image_url field in medication records: