DongfuJiang commited on
Commit
835bec4
1 Parent(s): 0f3b1a3
Files changed (1) hide show
  1. serve/log_server.py +4 -2
serve/log_server.py CHANGED
@@ -18,7 +18,8 @@ async def append_json(json_str: str = Form(...), file_name: str = Form(...)):
18
  # Convert the string back to a JSON object (dict)
19
  data = json.loads(json_str)
20
  # Append the data to the specified file
21
- os.makedirs(os.path.dirname(file_name), exist_ok=True)
 
22
  async with aiofiles.open(file_name, mode='a') as f:
23
  await f.write(json.dumps(data) + "\n")
24
 
@@ -31,7 +32,8 @@ async def save_image(image: UploadFile = File(...), image_path: str = Form(...))
31
  Saves an uploaded image to the specified path.
32
  """
33
  # Note: 'image_path' should include the file name and extension for the image to be saved.
34
- os.makedirs(os.path.dirname(image_path), exist_ok=True)
 
35
  async with aiofiles.open(image_path, mode='wb') as f:
36
  content = await image.read() # Read the content of the uploaded image
37
  await f.write(content) # Write the image content to a file
 
18
  # Convert the string back to a JSON object (dict)
19
  data = json.loads(json_str)
20
  # Append the data to the specified file
21
+ if os.path.dirname(file_name):
22
+ os.makedirs(os.path.dirname(file_name), exist_ok=True)
23
  async with aiofiles.open(file_name, mode='a') as f:
24
  await f.write(json.dumps(data) + "\n")
25
 
 
32
  Saves an uploaded image to the specified path.
33
  """
34
  # Note: 'image_path' should include the file name and extension for the image to be saved.
35
+ if os.path.dirname(image_path):
36
+ os.makedirs(os.path.dirname(image_path), exist_ok=True)
37
  async with aiofiles.open(image_path, mode='wb') as f:
38
  content = await image.read() # Read the content of the uploaded image
39
  await f.write(content) # Write the image content to a file