Documentation Index
Fetch the complete documentation index at: https://mintlify.com/Jesus-Puertos/h-ayuntamiento/llms.txt
Use this file to discover all available pages before exploring further.
Overview
The application uses Supabase Storage to store generated ticket images. This guide covers creating storage buckets, configuring access policies, and managing file uploads.Storage Architecture
- Maintain user privacy in file paths
- Enable user-specific access policies
- Simplify cleanup when users are deleted
Create Storage Bucket
Thetickets bucket stores generated route ticket images.
Automatic Creation (Recommended)
The Run the SQL script in SQL Editor to create it.
supabase-setup.sql script automatically creates the bucket:Manual Creation (If Needed)
If the bucket doesn’t exist:
- Go to Storage in Supabase dashboard
- Click New bucket
- Configure:
- Name:
tickets - Public bucket: ✅ Yes
- File size limit: 5 MB
- Allowed MIME types:
image/*
- Name:
- Click Create bucket
Configure Public Access
Thetickets bucket must be public to allow sharing generated ticket images.
Why Public?
Tickets need to be publicly accessible because:- Users share tickets on social media
- Shared routes display tickets to non-authenticated visitors
- No sensitive information is contained in tickets
Security Considerations
While the bucket is public, upload permissions are restricted to authenticated users only. Anyone can view files, but only authenticated users can create/modify their own files.
Upload Policies
The setup script creates these storage policies:View Policy (Public)
Upload Policy (Authenticated Users)
Update Policy (Own Files Only)
Delete Policy (Own Files Only)
File Organization
File Naming Convention
Benefits
- User isolation: Files are organized by user
- Easy cleanup: Delete all files when user is removed
- Policy enforcement: Folder structure enables user-specific policies
- Collision avoidance: User ID + route ID ensures uniqueness
Upload Implementation
Example code for uploading generated tickets:Upload Options
| Option | Description |
|---|---|
contentType | MIME type: 'image/png', 'image/jpeg', etc. |
cacheControl | Cache duration in seconds (e.g., '3600' = 1 hour) |
upsert | Replace existing file if true, fail if false |
Get Public URLs
Method 1: Direct Public URL
Method 2: Signed URL (If Not Public)
For the public
tickets bucket, use getPublicUrl(). Signed URLs are only necessary for private buckets.File Size Limits
Default Limits
- Free tier: 50 MB per file
- Pro tier: 5 GB per file
Configure Custom Limits
Frontend Validation
MIME Type Restrictions
Allow Only Images
Frontend Validation
CDN Integration
Supabase Storage automatically uses a CDN for better performance.CDN Benefits
✅ Automatic:- Global edge network
- Caching at edge locations
- Reduced latency worldwide
- No additional configuration needed
Cache Control Headers
Set cache headers when uploading:Cache Durations
| Type | Duration | Use Case |
|---|---|---|
3600 | 1 hour | Frequently updated files |
86400 | 1 day | Daily updated content |
604800 | 1 week | Stable content |
31536000 | 1 year | Immutable files (versioned) |
File Management
List Files
Delete File
Delete Multiple Files
Cleanup on User Deletion
Storage Quota Management
Check Usage
Monitor storage usage in Supabase dashboard:- Go to Settings → Usage
- View Storage metrics
- Check total size and bandwidth
Free Tier Limits
- Storage: 1 GB
- Bandwidth: 2 GB/month
- Files: Unlimited
Generated tickets are typically 200-500 KB each. 1 GB allows for approximately 2,000-5,000 tickets.
Optimize Storage Usage
-
Compress images before upload:
-
Delete old tickets:
-
Use WebP format (better compression):
Troubleshooting
Upload Fails with “new row violates row-level security”
Cause: Storage policies not configured or user not authenticated Solution:- Verify SQL script created all policies
- Check user is authenticated:
File Not Found (404)
Cause: Incorrect file path or bucket not public Solution:- Verify bucket is set to public
- Check file path matches upload path
- Ensure file was uploaded successfully
Large Files Timing Out
Solution:- Compress images before upload
- Increase timeout in client configuration
- Use chunked uploads for very large files
CORS Errors
Cause: Cross-origin requests blocked Solution: Supabase automatically handles CORS for storage. If issues persist:- Verify bucket is public
- Check that requests include proper headers
- Use
getPublicUrl()method for public access
Security Best Practices
✅ Recommended:- Keep upload permissions restricted to authenticated users
- Validate file types and sizes on both client and server
- Use user ID in file paths for isolation
- Set appropriate cache headers
- Monitor storage usage regularly
- Implement automatic cleanup of old files
- Allowing unauthenticated uploads
- Using predictable file names
- Storing sensitive information in public buckets
- Unlimited file sizes
- Ignoring storage quota limits
Advanced Configuration
Custom Storage Transformations
Supabase supports image transformations on the fly:Webhook Notifications
Set up webhooks for storage events:- Go to Database → Webhooks
- Create webhook for
storage.objectstable - Configure URL to receive notifications on uploads
Next Steps
After configuring storage:- Test file uploads
- Configure CDN caching
- Set up cleanup automation
- Monitor storage usage in Supabase dashboard
