tenraku.ou
2023-07-12 14:57:06 +09:00
3 changed files with 26 additions and 13 deletions

View File

@@ -8,16 +8,15 @@ kinton_router = r = APIRouter()
@r.post("/upload",)
async def upload(files:t.List[UploadFile] = File(...)):
async def upload(file:UploadFile = File(...)):
dataframes = []
for file in files:
if file.filename.endswith('.xlsx'):
try:
content = await file.read()
df = pd.read_excel(BytesIO(content))
dataframes.append(df)
except Exception as e:
raise HTTPException(status_code=400, detail=f"Error occurred while parsing file {file.filename}: {str(e)}")
else:
raise HTTPException(status_code=400, detail=f"File {file.filename} is not an Excel file")
return {"files": [file.filename for file in files]}
if file.filename.endswith('.xlsx'):
try:
content = await file.read()
df = pd.read_excel(BytesIO(content))
dataframes.append(df)
except Exception as e:
raise HTTPException(status_code=400, detail=f"Error occurred while parsing file {file.filename}: {str(e)}")
else:
raise HTTPException(status_code=400, detail=f"File {file.filename} is not an Excel file")
return {"file": file.filename}

View File

@@ -9,12 +9,25 @@ from app.core import config
# from app.core.auth import get_current_active_user
from app.core.celery_app import celery_app
from app import tasks
from fastapi.middleware.cors import CORSMiddleware
app = FastAPI(
title=config.PROJECT_NAME, docs_url="/api/docs", openapi_url="/api"
)
origins = [
"http://localhost:9000",
"http://localhost",
"http://localhost:8080",
]
app.add_middleware(
CORSMiddleware,
allow_origins=origins,
allow_credentials=True,
allow_methods=["*"],
allow_headers=["*"],
)
# @app.middleware("http")
# async def db_session_middleware(request: Request, call_next):

View File

@@ -7,6 +7,7 @@
:label="title"
accept=".csv,.xlsx"
:on-rejected="onRejected"
field-name="file"
></q-uploader>
</div>