Fix iOS hang when selecting many photos

Root cause: FileReader.readAsDataURL() loads the entire file into memory
as a base64 string. With 50+ iPhone photos (3-12 MB each), this exceeds
iOS Safari's per-tab memory limit and freezes the tab.

Changes:
- Replace readAsDataURL with URL.createObjectURL(file) — zero-copy file
  reference, no memory bloat (static/index.html)
- Reduce batch size from 4 to 2 — gentler on memory-constrained devices
- Add URL.revokeObjectURL() on reset — prevent blob URL leaks
- Add HEIC/HEIF support to server.py — iPhone format compatibility

Closes #1
This commit is contained in:
2026-05-25 16:20:04 -04:00
parent c1516471ac
commit 0052c59f81
9 changed files with 21 additions and 10 deletions
+10 -2
View File
@@ -6,6 +6,14 @@ from fastapi import FastAPI, File, Form, HTTPException, UploadFile
from fastapi.staticfiles import StaticFiles
from PIL import Image as PILImage
# Optional HEIC/HEIF support for iPhone photos
try:
from pillow_heif import register_heif_opener
register_heif_opener()
HAS_HEIF = True
except ImportError:
HAS_HEIF = False
try:
import pytesseract
HAS_TESSERACT = True
@@ -148,7 +156,7 @@ async def analyze_photo(file: UploadFile = File(...)):
file_size = len(contents)
ext = Path(file.filename or "photo.jpg").suffix.lower()
if ext not in {".jpg", ".jpeg", ".png", ".webp", ".bmp", ".tiff", ".tif", ".dng"}:
if ext not in {".jpg", ".jpeg", ".png", ".webp", ".bmp", ".tiff", ".tif", ".dng", ".heic", ".heif"}:
ext = ".jpg"
fname = f"{uuid.uuid4().hex}{ext}"
(UPLOADS / fname).write_bytes(contents)
@@ -194,7 +202,7 @@ async def bulk_process(files: list[UploadFile] = File(...)):
# Save
ext = Path(file.filename or "photo.jpg").suffix.lower()
if ext not in {".jpg", ".jpeg", ".png", ".webp", ".bmp", ".tiff", ".tif", ".dng"}:
if ext not in {".jpg", ".jpeg", ".png", ".webp", ".bmp", ".tiff", ".tif", ".dng", ".heic", ".heif"}:
ext = ".jpg"
fname = f"{uuid.uuid4().hex}{ext}"
(UPLOADS / fname).write_bytes(contents)