Skip to content

This project is a simple file sharing API built using FastAPI. It provides endpoints to upload, download, and retrieve metadata about files.

License

Notifications You must be signed in to change notification settings

AnalyticAce/FileShareAPI

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Simple-File-Sharing-API

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.

Features

  • 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.

Layout

  • Upload Page #1 Upload

  • Upload Page #2 Upload

  • Download Page Download

Technologies Used

  • Python
  • FastAPI: Web framework for building APIs.
  • JSON: For metadata storage.

Installation

  1. Clone the repository:

    git clone https://github.com/AnalyticAce/Simple-File-Sharing-API.git
    cd Simple-File-Sharing-API
    
  2. Set up a virtual environment (optional but recommended):

    python3 -m venv venv
    source venv/bin/activate  # On Windows: venv\Scripts\activate
    
  3. Install dependencies:

    pip install -r requirements.txt
    
  4. 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.

API Endpoints

Upload File

Endpoint: POST /file/upload/

Uploads a file to the server.

Request:

  • file: The file to upload (as multipart/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>"
}

Download File

Endpoint: GET /file/download/{file_id}

Downloads a file by its unique ID.

Response:

  • Returns the file as an attachment.

Get Metadata for All Files

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>"
  },
  ...
}

Get Metadata for a Specific File

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>"
}

Contributing

  1. Fork the repository.
  2. Create a new branch for your feature:
    git checkout -b feature/your-feature-name
    
  3. Commit your changes:
    git commit -m "Add your message here"
    
  4. Push to your branch:
    git push origin feature/your-feature-name
    
  5. Open a pull request.

License

This project is licensed under the MIT License. See the LICENSE file for details.

Acknowledgments

About

This project is a simple file sharing API built using FastAPI. It provides endpoints to upload, download, and retrieve metadata about files.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published