Jayra Ortiz
:bug: changed port number
8697050
raw
history blame contribute delete
989 Bytes
import uvicorn
from utils.settings import app
from fastapi import UploadFile
import aiofiles
from starlette import status
from starlette.responses import JSONResponse
from core.parser.task import extractor_task
@app.post("/api/parse-file")
async def upload_config_file_to_s3(
file: UploadFile
):
try:
file_path = f'./{file.filename}'
async with aiofiles.open(file_path, 'wb') as out_file:
content = await file.read() # async read
await out_file.write(content)
json_response = extractor_task(file_path)
return JSONResponse(
status_code=status.HTTP_200_OK,
content={"code": 200, "data": json_response},
)
except Exception as e:
return JSONResponse(
status_code=status.HTTP_400_BAD_REQUEST,
content={"code": 400, "message": f"{e}"},
)
if __name__ == "__main__":
uvicorn.run("main:app", host="0.0.0.0", port=7860, reload=True)