Spaces:
Paused
Paused
andreagalle commited on
Commit ·
e551281
1
Parent(s): 6b9a605
tmp directory which persists until manually deleted
Browse files
main.py
CHANGED
|
@@ -14,7 +14,8 @@ async def upload_zip(file: UploadFile = File(...)):
|
|
| 14 |
if not file.filename.endswith('.zip'):
|
| 15 |
raise HTTPException(status_code=400, detail="File must be a zip archive")
|
| 16 |
|
| 17 |
-
|
|
|
|
| 18 |
# Save the zip file to the temporary directory
|
| 19 |
zip_path = os.path.join(tmpdir, file.filename)
|
| 20 |
with open(zip_path, 'wb') as buffer:
|
|
@@ -74,6 +75,10 @@ async def upload_zip(file: UploadFile = File(...)):
|
|
| 74 |
|
| 75 |
# Return the .glb file as a response
|
| 76 |
return FileResponse(glb_file_path, media_type='application/octet-stream', filename=os.path.basename(glb_file_path))
|
|
|
|
|
|
|
|
|
|
|
|
|
| 77 |
|
| 78 |
if __name__ == '__main__':
|
| 79 |
import uvicorn
|
|
|
|
| 14 |
if not file.filename.endswith('.zip'):
|
| 15 |
raise HTTPException(status_code=400, detail="File must be a zip archive")
|
| 16 |
|
| 17 |
+
tmpdir = tempfile.mkdtemp()
|
| 18 |
+
try:
|
| 19 |
# Save the zip file to the temporary directory
|
| 20 |
zip_path = os.path.join(tmpdir, file.filename)
|
| 21 |
with open(zip_path, 'wb') as buffer:
|
|
|
|
| 75 |
|
| 76 |
# Return the .glb file as a response
|
| 77 |
return FileResponse(glb_file_path, media_type='application/octet-stream', filename=os.path.basename(glb_file_path))
|
| 78 |
+
|
| 79 |
+
finally:
|
| 80 |
+
# Cleanup: Remove the temporary directory and its contents
|
| 81 |
+
shutil.rmtree(tmpdir)
|
| 82 |
|
| 83 |
if __name__ == '__main__':
|
| 84 |
import uvicorn
|