update file
Browse files
api.py
CHANGED
@@ -7,6 +7,7 @@ from fastapi.middleware.cors import CORSMiddleware
|
|
7 |
|
8 |
app = FastAPI()
|
9 |
|
|
|
10 |
origins = ["*"]
|
11 |
|
12 |
app.add_middleware(
|
@@ -47,6 +48,11 @@ async def predict(file: UploadFile = File(...)):
|
|
47 |
if file.content_type not in ["image/jpeg", "image/png", "image/jpg"]:
|
48 |
raise HTTPException(status_code=400, detail="Invalid file type")
|
49 |
|
|
|
|
|
|
|
|
|
|
|
50 |
try:
|
51 |
image = read_file_as_image(image_data)
|
52 |
except HTTPException as e:
|
|
|
7 |
|
8 |
app = FastAPI()
|
9 |
|
10 |
+
# CORS yapılandırması
|
11 |
origins = ["*"]
|
12 |
|
13 |
app.add_middleware(
|
|
|
48 |
if file.content_type not in ["image/jpeg", "image/png", "image/jpg"]:
|
49 |
raise HTTPException(status_code=400, detail="Invalid file type")
|
50 |
|
51 |
+
# Dosya boyutunu kontrol et (örneğin, 5MB'den büyük dosyaları reddet)
|
52 |
+
max_file_size = 5 * 1024 * 1024 # 5MB
|
53 |
+
if len(image_data) > max_file_size:
|
54 |
+
raise HTTPException(status_code=400, detail="File size exceeds limit")
|
55 |
+
|
56 |
try:
|
57 |
image = read_file_as_image(image_data)
|
58 |
except HTTPException as e:
|