# Test Image Upload - Quick Verification

## Current Configuration

- **R2 Bucket**: `sojorn-media`
- **Account ID**: `7041ca6e0f40307190dc2e65e2fb5e0f`
- **Custom Domain**: `media.sojorn.net`
- **Upload URL**: `https://7041ca6e0f40307190dc2e65e2fb5e0f.r2.cloudflarestorage.com/sojorn-media`
- **Public URL**: `https://media.sojorn.net`

## Quick Test

### 1. Verify Custom Domain is Connected

Go to: https://dash.cloudflare.com → R2 → `sojorn-media` bucket → Settings

Under "Custom Domains", you should see:
- ✅ `media.sojorn.net` with status "Active"

If not connected:
1. Click "Connect Domain"
2. Enter: `media.sojorn.net`
3. Wait 1-2 minutes for activation

### 2. Test Upload in App

With the app running:
1. Tap compose button
2. Select an image
3. Add some text
4. Post

**Watch for**:
- Success notification
- Image appears in feed
- No error messages

### 3. Check What URL Was Generated

After uploading, check the database:

```sql
SELECT id, body, image_url, created_at
FROM posts
WHERE image_url IS NOT NULL
ORDER BY created_at DESC
LIMIT 1;
```

**Expected URL format**: `https://media.sojorn.net/[uuid].[ext]`

### 4. Test URL Directly

Copy the image_url from database and test in browser or curl:

```bash
curl -I https://media.sojorn.net/[filename-from-database]
```

**Expected response**: `HTTP/2 200 OK`

## Troubleshooting

### Edge Function Logs

Check for upload errors:
```bash
npx supabase functions logs upload-image --project-ref zwkihedetedlatyvplyz -f
```

Look for:
- ✅ "Successfully uploaded to R2"
- ❌ "Missing R2_PUBLIC_URL" (means secret not set)
- ❌ "R2 upload failed" (means authentication/permission issue)

### Environment Variables

Verify all secrets are set:
```bash
npx supabase secrets list --project-ref zwkihedetedlatyvplyz
```

Required secrets:
- ✅ R2_ACCOUNT_ID
- ✅ R2_ACCESS_KEY
- ✅ R2_SECRET_KEY
- ✅ R2_PUBLIC_URL

### Common Issues

| Issue | Cause | Solution |
|-------|-------|----------|
| Upload fails with 401 | Invalid R2 credentials | Check R2_ACCESS_KEY and R2_SECRET_KEY |
| Upload succeeds but image 404 | Domain not connected | Connect media.sojorn.net to bucket |
| "Missing R2_PUBLIC_URL" | Secret not set/propagated | Wait 2 minutes, redeploy function |
| Image loads slowly | Not cached | Normal for first load, subsequent loads cached |

## Expected Behavior

✅ **Upload Flow**:
1. User selects image → App processes/filters
2. App uploads to edge function → Edge function uploads to R2
3. Edge function returns: `https://media.sojorn.net/[uuid].jpg`
4. App saves post with image_url to database
5. Feed queries posts with image_url
6. PostItem widget displays image

✅ **Performance**:
- First upload: 2-5 seconds (depending on image size)
- Image load: <1 second (Cloudflare CDN)
- Subsequent loads: Instant (cached)

## Next Steps After Success

Once working:
1. Upload multiple images to test different sizes/formats
2. Test filters (grayscale, sepia, etc.)
3. Verify images show in all views (feed, profile, chains)
4. Check image quality and compression
5. Test on different devices/networks

## If Still Not Working

Share the following information:
1. Edge function logs (last 10 lines)
2. App console output (any errors)
3. Database query result (image_url value)
4. Cloudflare R2 bucket settings screenshot
5. Whether domain shows "Active" in R2 settings

---

**Everything is configured - ready to test now!** 🚀
