Add web upload: drag-and-drop images to depot via browser
Build & Deploy / build-and-deploy (push) Successful in 37s
Build & Deploy / build-and-deploy (push) Successful in 37s
- POST /api/upload saves files to /depot/ for ingest processing - Batches of 10 files per request - Drag-and-drop zone + file picker, per-file status feedback - New 'Last opp'-tab in navbar Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -156,6 +156,43 @@ async def get_results_endpoint(db=Depends(get_connection)):
|
||||
return await get_results(db)
|
||||
|
||||
|
||||
# =====================
|
||||
# Bildeopplasting
|
||||
# =====================
|
||||
|
||||
VALID_IMAGE_TYPES = {"image/jpeg", "image/png"}
|
||||
VALID_IMAGE_SUFFIXES = {".jpg", ".jpeg", ".png"}
|
||||
|
||||
|
||||
@app.post("/api/upload", summary="Last opp ett eller flere bilder til depot")
|
||||
async def upload_images(files: list[UploadFile] = File(...)):
|
||||
"""
|
||||
Lagrer opplastede bilder i /depot/ slik at ingest-prosessen plukker dem opp.
|
||||
Returnerer status per fil.
|
||||
"""
|
||||
results = []
|
||||
for file in files:
|
||||
suffix = Path(file.filename).suffix.lower()
|
||||
if suffix not in VALID_IMAGE_SUFFIXES:
|
||||
results.append({"filename": file.filename, "ok": False, "error": "Ugyldig filtype"})
|
||||
continue
|
||||
|
||||
dest = Path("/depot") / file.filename
|
||||
# Unngå overskrivning ved navnekollisjon
|
||||
if dest.exists():
|
||||
import uuid as _uuid
|
||||
dest = Path("/depot") / f"{_uuid.uuid4().hex}_{file.filename}"
|
||||
|
||||
try:
|
||||
content = await file.read()
|
||||
dest.write_bytes(content)
|
||||
results.append({"filename": file.filename, "ok": True, "saved_as": dest.name})
|
||||
except Exception as e:
|
||||
results.append({"filename": file.filename, "ok": False, "error": str(e)})
|
||||
|
||||
return {"uploaded": sum(1 for r in results if r["ok"]), "results": results}
|
||||
|
||||
|
||||
# =====================
|
||||
# Bilder
|
||||
# =====================
|
||||
|
||||
Reference in New Issue
Block a user