# 🗄️ Object Storage Setup Guide

## Problem: Images Disappearing After a Few Hours

Your website was saving uploaded images to the local filesystem (`static/images/`), which is **ephemeral storage** in Replit. This means files get automatically deleted after a few hours.

## Solution: Replit Object Storage (Persistent Storage)

I've updated your website to use **Replit Object Storage**, which is built on Google Cloud Storage and provides permanent file storage.

---

## 📋 Setup Instructions (Required)

### Step 1: Create an Object Storage Bucket

1. Open the **Tools** panel in your Replit workspace (left sidebar)
2. Click on **Object Storage**
3. Click **"Create a Bucket"**
4. Give it a name (e.g., `ftc-team-images`)
5. Click **Create**

### Step 2: Set Environment Variable

1. Go to the **Secrets** tab in your Replit workspace (lock icon in left sidebar)
2. Add a new secret:
   - **Key**: `OBJECT_STORAGE_BUCKET`
   - **Value**: Your bucket name (e.g., `ftc-team-images`)
3. Click **Add Secret**

### Step 3: Restart the Server

1. Stop the Flask server if it's running
2. Start it again (or let it auto-restart)

---

## ✅ How It Works Now

### Automatic Upload to Persistent Storage

All file uploads now go to Object Storage instead of local storage:

- **Member/Mentor Photos** → `members/` folder in your bucket
- **Competition Images** → `competitions/` folder  
- **Sponsor Logos** → `sponsors/` folder

### Full Image URLs

Images are now stored as **full Google Cloud Storage URLs** like:
```
https://storage.googleapis.com/ftc-team-images/members/abc123.jpg
```

These URLs are:
- ✅ **Permanent** - Never get deleted
- ✅ **Fast** - Served directly from Google's CDN
- ✅ **Public** - Accessible from anywhere on the web
- ✅ **Reliable** - Backed by Google Cloud infrastructure

---

## 🔧 Code Changes Made

### New Files:
- `object_storage.py` - Object storage service module
- `OBJECT_STORAGE_SETUP.md` - This guide

### Updated Files:
- `app.py` - All upload routes now use object storage
  - `add_member()` - Member/mentor images
  - `update_member()` - Member/mentor updates
  - `add_competition()` - Competition images
  - `edit_competition()` - Competition image updates
  - `add_sponsor()` - Sponsor logos

### Updated Dependencies:
- Added `google-cloud-storage` package

---

## 🚀 Testing

After setup, test by:

1. Go to `/admin/login` (password: `techturb123`)
2. Upload a new member photo or competition image
3. Check that the image displays correctly
4. Wait a few hours - the image should still be there!

---

## 🔒 Security Notes

- Object storage is authenticated automatically via Replit's infrastructure
- All uploaded files are made publicly accessible (required for website images)
- Files are organized into folders for easy management
- Each file gets a unique UUID to prevent naming conflicts

---

## ⚠️ Important: Fallback Mode

If you haven't set up object storage yet, the website will still work using local storage (ephemeral):
- You'll see a warning in the console: `"Warning: Object Storage not configured"`
- Files will still be saved but **will disappear after a few hours**
- Set up object storage ASAP to make uploads permanent!

---

## 📚 Additional Resources

- [Replit Object Storage Docs](https://docs.replit.com/hosting/deployments/object-storage)
- [Google Cloud Storage](https://cloud.google.com/storage)

---

**Need Help?** If you have any issues with setup, check the console logs for error messages.
