Skip to content

SelimArslan1/file-share

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

File Sharing System

A secure file sharing application that allows users to upload files and generate shareable URLs. Built with Spring Boot and PostgreSQL, featuring JWT authentication and comprehensive file management capabilities.

Features

  • User Authentication: Secure registration and login system
  • File Upload: Upload files and receive shareable download URLs
  • File Download: Access files via unique download tokens
  • Admin Controls: Administrative file deletion capabilities
  • Download Tracking: Comprehensive logging of file downloads
  • JWT Security: Token-based authentication for protected routes

Technology Stack

  • Backend: Spring Boot (Java 20)
  • Database: PostgreSQL
  • Authentication: JWT (JSON Web Tokens)
  • Build Tool: Maven
  • Containerization: Docker & Docker Compose

Prerequisites

  • Java 20 or higher
  • Maven
  • Docker and Docker Compose
  • PostgreSQL (via Docker)

Setup Instructions

1. Clone the Repository

git clone https://github.com/SelimArslan1/file-share

2. Environment Configuration

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

POSTGRES_DB=your_database_name
POSTGRES_USER=your_postgres_user
POSTGRES_PASSWORD=your_postgres_password
SPRING_DATASOURCE_URL=jdbc:postgresql://localhost:5432/your_database_name
SPRING_DATASOURCE_USERNAME=your_postgres_user
SPRING_DATASOURCE_PASSWORD=your_postgres_password

3. Build and Run

mvn clean package -DskipTests

# Start the application with Docker Compose
docker-compose up --build

The application will be available at http://localhost:8080

API Routes

Public Routes (No Authentication Required)

User Registration

POST /auth/register
Content-Type: application/json

{
    "username": "your_username",
    "email": "your_email@example.com",
    "password": "your_password",
    "repeatedPassword": "your_password"
}

User Login

POST /auth/login
Content-Type: application/json

{
    "email": "your_email",
    "password": "your_password"
}

Protected Routes (JWT Token Required)

File Upload

POST /files/upload
Authorization: Bearer <your_jwt_token>
Content-Type: multipart/form-data

Form Data:
- file: [your file]

Response: Returns a shareable download URL with unique token

File Download

GET /files/download/{downloadToken}
Authorization: Bearer <your_jwt_token>

Admin Routes (Admin JWT Token Required)

Delete File

DELETE /admin/delete
Authorization: Bearer <admin_jwt_token>
Content-Type: application/json

{
    "downloadToken": "download_token"
}

Testing with Postman

1. Register a New User

  • Method: POST
  • URL: http://localhost:8080/auth/register
  • Headers: Content-Type: application/json
  • Body (raw JSON):
{
    "username": "testuser",
    "email": "test@example.com",
    "password": "securepassword123",
    "repeatedPassword": "securepassword123"
}

2. Login

  • Method: POST
  • URL: http://localhost:8080/auth/login
  • Headers: Content-Type: application/json
  • Body (raw JSON):
{
    "email": "test@example.com",
    "password": "securepassword123"
}
  • Note: Copy the JWT token from the response for subsequent requests

3. Upload a File

  • Method: POST
  • URL: http://localhost:8080/files/upload
  • Headers:
    • Authorization: Bearer <your_jwt_token>
  • Body:
    • Type: form-data
    • Key: file
    • Value: Select your file

4. Download a File

  • Method: GET
  • URL: http://localhost:8080/files/download/{downloadToken}
  • Headers: Authorization: Bearer <your_jwt_token>

5. Admin Delete (Admin only)

  • Method: DELETE
  • URL: http://localhost:8080/admin/delete
  • Headers:
    • Authorization: Bearer <admin_jwt_token>
    • Content-Type: application/json
  • Body (raw JSON):
{
    "downloadToken": "download_token"
}

Database Schema

The application uses PostgreSQL with the following main entities:

  • Users: User account information and credentials
  • Files: File metadata including upload information and download tokens
  • Download Logs: Tracking and analytics for file downloads

Security Features

  • JWT Authentication: All protected routes require valid JWT tokens
  • Role-based Access: Admin routes restricted to admin users
  • Secure File Access: Files accessible only via unique download tokens
  • Password Encryption: User passwords are securely hashed
  • Download Tracking: All file access is logged for security monitoring

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors