yifan0sun commited on
Commit
27ab4ec
·
verified ·
1 Parent(s): 2249c0c

Update server.py

Browse files
Files changed (1) hide show
  1. server.py +13 -6
server.py CHANGED
@@ -70,18 +70,25 @@ def ping():
70
  @app.post("/upload_to_path")
71
  async def upload_to_path(
72
  file: UploadFile = File(...),
73
- dest_path: str = Form(...) # e.g., "models/model.pt"
74
  ):
75
- full_path = Path("/data") / dest_path
76
- full_path.parent.mkdir(parents=True, exist_ok=True)
77
 
78
- with open(full_path, "wb") as f:
79
- f.write(await file.read())
 
80
 
81
- return {"status": "uploaded", "path": str(full_path)}
 
82
 
 
 
 
83
 
 
84
 
 
85
 
86
  @app.post("/make_dir")
87
  def make_directory(
 
70
  @app.post("/upload_to_path")
71
  async def upload_to_path(
72
  file: UploadFile = File(...),
73
+ dest_path: str = Form(...)
74
  ):
75
+ base_path = Path("/data")
76
+ target_path = base_path / dest_path
77
 
78
+ # If the path ends with "/", or is a directory, treat it as a folder
79
+ if str(dest_path).endswith("/") or target_path.is_dir():
80
+ target_path = target_path / file.filename
81
 
82
+ # Ensure parent directories exist
83
+ target_path.parent.mkdir(parents=True, exist_ok=True)
84
 
85
+ # Write file
86
+ with open(target_path, "wb") as f:
87
+ f.write(await file.read())
88
 
89
+ return {"status": "uploaded", "path": str(target_path)}
90
 
91
+
92
 
93
  @app.post("/make_dir")
94
  def make_directory(