This project is a simple file sharing API built using FastAPI. It provides endpoints to upload, download, and retrieve metadata about files. The uploaded files are stored in a folder, and metadata is managed in a JSON file.
- File Upload: Upload files to the server with metadata tracking.
- File Download: Securely download files by their unique ID.
- Metadata Retrieval: Access metadata for all files or a specific file.
- Download Count Tracking: Monitor how many times each file has been downloaded.
- Python
- FastAPI: Web framework for building APIs.
- JSON: For metadata storage.
-
Clone the repository:
git clone https://github.com/AnalyticAce/Simple-File-Sharing-API.git cd Simple-File-Sharing-API
-
Set up a virtual environment (optional but recommended):
python3 -m venv venv source venv/bin/activate # On Windows: venv\Scripts\activate
-
Install dependencies:
pip install -r requirements.txt
-
Run the server:
fastapi run app/main.py --host 0.0.0.0 --port 8080 --reload
The server will be accessible at http://0.0.0.0:8080
.
Endpoint: POST /file/upload/
Uploads a file to the server.
Request:
file
: The file to upload (asmultipart/form-data
).
Response:
{
"file_id": "<unique_file_id>",
"original_name": "<original_filename>",
"content_type": "<file_mime_type>",
"file_size": <file_size_in_bytes>,
"download_link": "<download_url>"
}
Endpoint: GET /file/download/{file_id}
Downloads a file by its unique ID.
Response:
- Returns the file as an attachment.
Endpoint: GET /file/metadata/
Retrieves metadata for all uploaded files.
Response:
{
"<file_id>": {
"original_name": "<original_filename>",
"content_type": "<file_mime_type>",
"file_size": <file_size_in_bytes>,
"download_count": <download_count>,
"download_link": "<download_url>"
},
...
}
Endpoint: GET /file/metadata/{file_id}
Retrieves metadata for a specific file by its unique ID.
Response:
{
"original_name": "<original_filename>",
"content_type": "<file_mime_type>",
"file_size": <file_size_in_bytes>,
"download_count": <download_count>,
"download_link": "<download_url>"
}
- Fork the repository.
- Create a new branch for your feature:
git checkout -b feature/your-feature-name
- Commit your changes:
git commit -m "Add your message here"
- Push to your branch:
git push origin feature/your-feature-name
- Open a pull request.
This project is licensed under the MIT License. See the LICENSE
file for details.
- FastAPI documentation: https://fastapi.tiangolo.com/