Overview
PC Fix uses Cloudinary for:- Product Images: Automatically converted to WebP format for optimal performance
- Receipt Uploads: Supports images and PDF files for payment verification
- CDN Delivery: Fast global content delivery through Cloudinary’s CDN
Configuration
Create a Cloudinary Account
Sign up for a free account at cloudinary.com. The free tier includes 25GB storage and 25GB bandwidth per month.
Get Your API Credentials
Navigate to your Cloudinary Dashboard and copy:
- Cloud Name
- API Key
- API Secret
Never commit your
.env file to version control. Cloudinary credentials should remain secret.Implementation
Upload Middleware
Cloudinary is configured in the upload middleware atpackages/api/src/shared/middlewares/uploadMiddleware.ts:
Upload Instances
Two multer instances are exported for different use cases:Usage Examples
Uploading Product Images
Use theupload middleware in your routes:
Uploading Receipts
Use theuploadReceipt middleware for payment verification:
Frontend Configuration
To enable Cloudinary URLs in Astro, add the domain to yourastro.config.mjs:
astro.config.mjs
Layout.astro
Folder Structure
Cloudinary organizes uploads into folders:pcfix-products/- Product images (auto-converted to WebP)pcfix-receipts/- Payment receipts (images and PDFs)
File Constraints
Product Images
- Max Size: 5MB
- Formats: JPEG, PNG, WebP, GIF
- Output: Auto-converted to WebP
Receipts
- Max Size: 10MB
- Formats: JPEG, PNG, WebP, GIF, PDF
- Output: Original format preserved
Benefits
Automatic Optimization
Automatic Optimization
Product images are automatically converted to WebP format, reducing file size by up to 30% while maintaining quality.
Global CDN
Global CDN
Images are delivered through Cloudinary’s global CDN, ensuring fast load times for users worldwide.
Unique File Names
Unique File Names
Files are automatically renamed using timestamps and random numbers to prevent collisions.
Scalable Storage
Scalable Storage
No need to manage file storage on your server. Cloudinary handles all storage and scaling automatically.
Troubleshooting
Upload fails with 401 error
Upload fails with 401 error
Check that your
CLOUDINARY_API_KEY and CLOUDINARY_API_SECRET are correct in your .env file.Images not loading in frontend
Images not loading in frontend
Ensure
res.cloudinary.com is added to the domains array in astro.config.mjs.File size too large
File size too large
Product images are limited to 5MB, receipts to 10MB. Compress images before uploading or adjust the limits in
uploadMiddleware.ts.Security Considerations
- API credentials are validated server-side only
- File type restrictions prevent unauthorized file uploads
- Unique file names prevent directory traversal attacks
- CORS configuration restricts access to authorized domains