MarioPrzBasto commited on
Commit
c8aef77
·
verified ·
1 Parent(s): b065640

Update main.py

Browse files
Files changed (1) hide show
  1. main.py +6 -4
main.py CHANGED
@@ -1,5 +1,5 @@
1
  from typing import List
2
- from fastapi import FastAPI, HTTPException, Request
3
  from fastapi.responses import JSONResponse
4
  import os
5
  import json
@@ -10,9 +10,11 @@ app = FastAPI()
10
  BASE_DIR = "/tmp/data"
11
 
12
  @app.post("/save")
13
- async def save(request: Request):
14
- body = await request.body()
15
- print("RAW BODY RECEIVED ", body.decode())
 
 
16
  return True
17
 
18
  @app.get("/files")
 
1
  from typing import List
2
+ from fastapi import FastAPI, HTTPException
3
  from fastapi.responses import JSONResponse
4
  import os
5
  import json
 
10
  BASE_DIR = "/tmp/data"
11
 
12
  @app.post("/save")
13
+ async def save(image_data: RequestModel):
14
+ os.makedirs(BASE_DIR, exist_ok=True)
15
+ filename = os.path.join(BASE_DIR, f"{image_data.originId}_{image_data.assetCode}.json")
16
+ with open(filename, "w") as f:
17
+ json.dump(image_data.dict(), f, indent=4)
18
  return True
19
 
20
  @app.get("/files")