CORS対応
This commit is contained in:
@@ -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}
|
||||
|
||||
@@ -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):
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
:label="title"
|
||||
accept=".csv,.xlsx"
|
||||
:on-rejected="onRejected"
|
||||
field-name="file"
|
||||
></q-uploader>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
Reference in New Issue
Block a user