slimshadow commited on
Commit
7aee092
·
verified ·
1 Parent(s): 7ab93cb

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +11 -3
app.py CHANGED
@@ -1,10 +1,18 @@
1
- from fastapi import FastAPI
2
  from fastapi.middleware.gzip import GZipMiddleware
 
 
 
3
 
4
  app = FastAPI()
 
 
5
  app.add_middleware(GZipMiddleware, minimum_size=1000)
6
 
7
- # Your existing routes
 
 
 
8
  @app.post("/upload/")
9
  async def upload_file(file: UploadFile = File(...)):
10
  file_path = os.path.join(UPLOAD_DIR, file.filename)
@@ -17,4 +25,4 @@ async def download_file(filename: str):
17
  file_path = os.path.join(UPLOAD_DIR, filename)
18
  if os.path.exists(file_path):
19
  return FileResponse(file_path, media_type='application/octet-stream', filename=filename)
20
- return {"error": "File not found"}
 
1
+ from fastapi import FastAPI, File, UploadFile
2
  from fastapi.middleware.gzip import GZipMiddleware
3
+ from fastapi.responses import FileResponse
4
+ import os
5
+ import shutil
6
 
7
  app = FastAPI()
8
+
9
+ # Enable gzip compression
10
  app.add_middleware(GZipMiddleware, minimum_size=1000)
11
 
12
+ # Directory to store uploaded files
13
+ UPLOAD_DIR = "/app/uploads"
14
+ os.makedirs(UPLOAD_DIR, exist_ok=True)
15
+
16
  @app.post("/upload/")
17
  async def upload_file(file: UploadFile = File(...)):
18
  file_path = os.path.join(UPLOAD_DIR, file.filename)
 
25
  file_path = os.path.join(UPLOAD_DIR, filename)
26
  if os.path.exists(file_path):
27
  return FileResponse(file_path, media_type='application/octet-stream', filename=filename)
28
+ return {"error": "File not found"}