Migrate all website images to permanent cloud storage

Update application to utilize Replit Object Storage for all uploaded member, competition, and sponsor images, ensuring permanent storage and updating database paths accordingly.

Replit-Commit-Author: Agent
Replit-Commit-Session-Id: cd9a7d26-a4e5-4215-975c-c59f4ed1f06d
Replit-Commit-Checkpoint-Type: full_checkpoint
Replit-Commit-Event-Id: 74506617-f398-426d-a3f7-aa9d2fbde85b
Replit-Commit-Screenshot-Url: https://storage.googleapis.com/screenshot-production-us-central1/d0a1d46d-d203-4308-bc6a-312ac7c0243b/cd9a7d26-a4e5-4215-975c-c59f4ed1f06d/62gjmyB
This commit is contained in:
abhiramtx
2025-12-13 21:47:55 +00:00
parent d7532b7134
commit 4852e2c153
2 changed files with 18 additions and 147 deletions

View File

@@ -3,39 +3,28 @@
## Overview
Flask-based website for FTC Team 23344 with a modern dark theme (#000000 pure black background), comprehensive content management system, PostgreSQL database integration, and premium smooth-scrolling animations.
## Recent Changes (November 13, 2025)
## Recent Changes (December 13, 2025)
### Critical Fix: Persistent Object Storage for Uploaded Files
Fixed the issue where uploaded images (members, mentors, competitions, sponsors) were disappearing after a few hours.
### Complete Object Storage Migration
All uploaded images are now stored permanently in Replit Object Storage, preventing the issue where files would disappear after a few hours.
**The Problem:**
- Files were being saved to local filesystem (`static/images/`)
- Local storage in Replit is **ephemeral** and gets cleared periodically
- All uploaded images would vanish after a few hours
**What Was Done:**
1. Installed `replit-object-storage` official Python package
2. Created `object_storage.py` using official Replit SDK
3. Added `/storage/<path>` route to serve files from object storage
4. Added `|image_url` Jinja template filter to handle both local and storage paths
5. Migrated all existing member, mentor, competition, and sponsor images to object storage
6. Updated database paths from `images/filename.jpg` to `/storage/folder/uuid.ext`
**The Solution:**
- Migrated to **Replit Object Storage** (built on Google Cloud Storage)
- All file uploads now go to **persistent, permanent storage**
- Images are served directly from Google's CDN with full URLs
**How It Works:**
- New uploads go directly to object storage via `upload_file_to_storage()` helper
- Database stores paths like `/storage/members/uuid.png`
- Templates use `{{ image_path|image_url }}` filter which handles both formats
- `/storage/` route serves files from object storage bucket
- Background images (hero, team, etc.) remain local as they don't get erased
**Technical Implementation:**
- Created `object_storage.py` module using Google Cloud Storage Python client
- Updated all upload routes to use object storage:
- `add_member()`, `update_member()` - Member/mentor photos
- `add_competition()`, `edit_competition()` - Competition images
- `add_sponsor()` - Sponsor logos
- Intelligent fallback: uses local storage if object storage not configured
- Files organized by type: `members/`, `competitions/`, `sponsors/` folders
- Unique UUIDs prevent filename conflicts
- Public URLs stored in database instead of local paths
**Setup Required (See OBJECT_STORAGE_SETUP.md):**
1. Create bucket in Object Storage pane
2. Set `OBJECT_STORAGE_BUCKET` environment variable
3. Restart server
**Dependencies Added:**
- `google-cloud-storage` (v3.5.0)
**Bucket:** `ftc-team-images`
**Package:** `replit-object-storage` (installed via pip)
## Recent Changes (November 12, 2025)