rayhanzuck commited on
Commit
e1d6b2a
·
verified ·
1 Parent(s): 791798b

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +20 -0
app.py ADDED
@@ -0,0 +1,20 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from fastapi import FastAPI, File, UploadFile
2
+ from fastapi.staticfiles import StaticFiles
3
+ import os
4
+
5
+ app = FastAPI()
6
+
7
+ UPLOAD_FOLDER = "uploads"
8
+ os.makedirs(UPLOAD_FOLDER, exist_ok=True)
9
+
10
+ @app.post("/upload/")
11
+ async def upload_file(file: UploadFile = File(...)):
12
+ file_path = os.path.join(UPLOAD_FOLDER, file.filename)
13
+
14
+ with open(file_path, "wb") as f:
15
+ f.write(await file.read())
16
+
17
+ return {"message": "File berhasil diunggah!", "file_url": f"/uploads/{file.filename}"}
18
+
19
+ # Menyediakan file yang diunggah agar bisa diakses publik
20
+ app.mount("/uploads", StaticFiles(directory="uploads"), name="uploads")