From 6b70d9120117af25a777f096a00d398b6ebfa08a Mon Sep 17 00:00:00 2001 From: Stranck Date: Thu, 4 Jan 2024 22:15:02 +0100 Subject: [PATCH] Fixed propic upload limits If the size is bigger than 5MB the error will be handled by SANIC directly. Maybe we'd like a better user-visible handling? --- app.py | 2 ++ propic.py | 2 ++ 2 files changed, 4 insertions(+) diff --git a/app.py b/app.py index fa2a1b1..ccb1102 100644 --- a/app.py +++ b/app.py @@ -47,6 +47,8 @@ async def clear_session(request, exception): @app.before_server_start async def main_start(*_): print(">>>>>> main_start <<<<<<") + + app.config.REQUEST_MAX_SIZE = 1024 * 1024 * 5 # 5 MB app.ctx.om = OrderManager() if FILL_CACHE: diff --git a/propic.py b/propic.py index 7eef9b4..907caa9 100644 --- a/propic.py +++ b/propic.py @@ -45,6 +45,8 @@ async def upload_propic(request, order: Order): try: img = Image.open(BytesIO(body[0].body)) + if(img.size[0] > 2048 or img.size[1] > 2048): + raise exceptions.BadRequest("Maximum allowed dimensions: 2048x2048") with open(f"res/propic/{fn}_{order.code}_original", "wb") as f: f.write(body[0].body)