feat(storage): add S3 image storage support with file-based config and migration script
This commit is contained in:
@@ -13,7 +13,7 @@ from app.models import (
|
||||
PERM_POSTCARDS_READ, PERM_POSTCARDS_WRITE,
|
||||
PERM_IMAGES_UPLOAD,
|
||||
)
|
||||
from app.config import UPLOAD_DIR
|
||||
# config removed: image storage now via app.storage
|
||||
|
||||
router = APIRouter(prefix="/api/v1", tags=["api"])
|
||||
|
||||
@@ -380,15 +380,16 @@ async def upload_image(
|
||||
ak: ApiKey = Depends(require_scopes(PERM_IMAGES_UPLOAD)),
|
||||
):
|
||||
pc = _postcard_or_404(ak.user, profile_id, postcard_id, db)
|
||||
from app.storage import get_storage
|
||||
storage = get_storage()
|
||||
ext = Path(file.filename).suffix if file.filename else ".jpg"
|
||||
save_name = f"pc_{pc.id}_{side}{ext}"
|
||||
save_path = UPLOAD_DIR / save_name
|
||||
key = f"pc_{pc.id}_{side}{ext}"
|
||||
content = await file.read()
|
||||
save_path.write_bytes(content)
|
||||
storage.put(key, content)
|
||||
if side == "front":
|
||||
pc.image_front = f"/uploads/{save_name}"
|
||||
pc.image_front = key
|
||||
else:
|
||||
pc.image_back = f"/uploads/{save_name}"
|
||||
pc.image_back = key
|
||||
db.commit()
|
||||
db.refresh(pc)
|
||||
return pc
|
||||
|
||||
Reference in New Issue
Block a user