Spaces:
Running
on
T4
Running
on
T4
Update server.py
Browse files
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(...)
|
74 |
):
|
75 |
-
|
76 |
-
|
77 |
|
78 |
-
with
|
79 |
-
|
|
|
80 |
|
81 |
-
|
|
|
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(
|