JulienHalgand commited on
Commit
19ec7d1
·
1 Parent(s): 9d02239

Test container

Browse files
Files changed (1) hide show
  1. app.py +5 -6
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 greet_json():
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
- file_location = f"uploads/{file.filename}"
16
- with open(file_location, "wb") as f:
17
  shutil.copyfileobj(file.file, f)
18
- return FileResponse(path=file_location, filename=file.filename)
 
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)