Spaces:
Sleeping
Sleeping
Commit
·
19ec7d1
1
Parent(s):
9d02239
Test container
Browse files
app.py
CHANGED
@@ -1,18 +1,17 @@
|
|
1 |
from fastapi import FastAPI, UploadFile, File
|
2 |
from fastapi.responses import FileResponse
|
3 |
-
import os
|
4 |
-
import shutil
|
5 |
|
6 |
app = FastAPI()
|
7 |
|
8 |
@app.get("/")
|
9 |
-
def
|
10 |
return {"Hello": "World!"}
|
11 |
|
12 |
@app.post("/upload")
|
13 |
async def upload_file(file: UploadFile = File(...)):
|
14 |
os.makedirs("uploads", exist_ok=True)
|
15 |
-
|
16 |
-
with open(
|
17 |
shutil.copyfileobj(file.file, f)
|
18 |
-
return FileResponse(
|
|
|
1 |
from fastapi import FastAPI, UploadFile, File
|
2 |
from fastapi.responses import FileResponse
|
3 |
+
import os, shutil
|
|
|
4 |
|
5 |
app = FastAPI()
|
6 |
|
7 |
@app.get("/")
|
8 |
+
def root():
|
9 |
return {"Hello": "World!"}
|
10 |
|
11 |
@app.post("/upload")
|
12 |
async def upload_file(file: UploadFile = File(...)):
|
13 |
os.makedirs("uploads", exist_ok=True)
|
14 |
+
filepath = f"uploads/{file.filename}"
|
15 |
+
with open(filepath, "wb") as f:
|
16 |
shutil.copyfileobj(file.file, f)
|
17 |
+
return FileResponse(filepath, filename=file.filename)
|