Giter Site home page Giter Site logo

karimtayie / file-extension-websocket Goto Github PK

View Code? Open in Web Editor NEW
0.0 1.0 0.0 44 KB

This project implements a WebSocket service using Django that allows clients to send a file to the server. The server then identifies the file's extension and returns this information to the client.

Python 78.47% HTML 21.53%

file-extension-websocket's Introduction

File Extension Identification via WebSocket in Django

This project implements a WebSocket service using Django that allows clients to send a file to the server. The server then identifies the file's extension and returns this information to the client.

Key Features

  • WebSocket Setup: Implements the WebSocket connection using Django Channels.
  • File Processing: Accepts a file over the WebSocket, determines its extension, and communicates this back to the client.
  • Security Measures: Addresses common security concerns to ensure safe file handling.
  • Documentation: Thoroughly documents the setup, usage, dependencies, and interaction with the WebSocket service.

Getting Started

Prerequisites

  • Python 3.12

Installation

  1. Clone the repository:

    git clone https://github.com/KarimTayie/file-extension-websocket.git
    cd file-extension-websocket
  2. Create a virtual environment:

    python3 -m venv env
    source env/bin/activate  # Linux/Mac
    # OR
    .\env\Scripts\activate   # Windows
  3. Install dependencies:

    pip install -r requirements.txt

    This project relies on python-magic. Ensure that libmagic is installed on your system:

    • Debian/Ubuntu:

      sudo apt-get install libmagic1
    • Windows: You'll need DLLs for libmagic. You can fetch them with:

      pip install python-magic-bin
    • macOS:

      • When using Homebrew:
        brew install libmagic
      • When using MacPorts:
        port install file
  4. Set up environment variables:

    Create a .env file in the project root directory and define the following variables:

    SECRET_KEY=<your_secret_key>
    DEBUG=True
    MAX_ALLOWED_SIZE=<max_allowed_size_in_megabytes>
    

Usage

  1. Start the Django development server:

    python manage.py runserver
  2. Navigate to http://localhost:8000/fe/upload/ in your web browser to access the file upload form.

  3. Choose a file and click the "Send File" button. The file extension will be identified and displayed on the page.

WebSocket Configuration

  • The WebSocket endpoint for file extension identification is located at ws://localhost:8000/ws/file_extension/.

Notes

  • The maximum allowed size for uploaded files is defined by the MAX_ALLOWED_SIZE environment variable in the .env file.
  • Files exceeding the maximum allowed size will result in a validation error.
  • File extensions are identified using the python-magic library along with MIME type detection.

file-extension-websocket's People

Contributors

karimtayie avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.