Skip to content

Commit 56a432c

Browse files
committed
➕ Added middleware for fileuploadsize
1 parent f652be5 commit 56a432c

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

src/paste/main.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
from slowapi import Limiter, _rate_limit_exceeded_handler
1111
from slowapi.util import get_remote_address
1212
from .utils import generate_uuid
13+
from .middleware import LimitUploadSize
1314

1415
limiter = Limiter(key_func=get_remote_address)
1516
app = FastAPI(title="paste.py 🐍")
@@ -26,6 +27,8 @@
2627
allow_headers=["*"],
2728
)
2829

30+
app.add_middleware(LimitUploadSize, max_upload_size=20_000_000) # ~20MB
31+
2932
large_uuid_storage = []
3033

3134
BASE_DIR = Path(__file__).resolve().parent
@@ -58,7 +61,7 @@ async def post_as_a_file(request: Request, file: UploadFile = File(...)):
5861

5962

6063
@app.get("/paste/{uuid}")
61-
async def post_as_a_text(uuid):
64+
async def get_paste_data(uuid):
6265
path = f"data/{uuid}"
6366
try:
6467
with open(path, "rb") as f:

0 commit comments

Comments
 (0)