A simple FastAPI app to upload files, JSON, and text to MongoDB Atlas GridFS, with a basic HTML frontend.
- Upload: PDFs, images (
.jpg,.png), JSON, text. - Storage: Separate GridFS buckets (
pdf,image,other). - Frontend: Upload, list, download, update, delete via UI.
-
Clone (if using Git):
git clone https://github.com/saifulislam735/File-Upload-API.git cd File-Upload-API -
Virtual Env:
python -m venv venv venv\Scripts\activate # Windows
-
Install:
pip install fastapi uvicorn pymongo python-dotenv python-multipart
-
MongoDB:
- Get URI from mongodb.com.
- Add to
.env:MONGODB_URI=mongodb+srv://myuser:mypassword@cluster0.xyz123.mongodb.net/?retryWrites=true&w=majority
-
Run API: for share link in the same network
uvicorn app.main:app --reload --host 0.0.0.0 --port 8000
or for your own machine
python -m uvicorn app.main:app --host 127.0.0.1 --port 8000 --reload
-
Run Frontend:
cd E:\Frontend python -m http.server 8001
- URL:
http://172.16.225.76:8001
- URL:
- API:
http://172.16.225.76:8000POST /upload/: File, JSON, or text.GET /files/: List all.GET /file/{file_id}/{bucket}: Download.PUT /file/{file_id}/{bucket}: Update.DELETE /file/{file_id}/{bucket}: Delete.
- Frontend: Upload and manage via UI.
- Within Same Network
- API:
http://172.16.225.76:8000/docs - UI:
http://172.16.225.76:8001
- API:
- No Access: Check Wi-Fi, allow port 8000 in firewall.
- Errors: Verify
.envURI, ensure server’s running.
[User] → 📂 Pick File → 🌐 Frontend → ⚙️ Backend → 🗄️ Database → 📩 Response