Skip to content

codingwitharmand/filemanagement

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

3 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

File Management System

A comprehensive document management system built with Spring Boot that allows users to upload, download, search, and manage files through both a web interface and a REST API.

Features

  • Upload files with optional descriptions
  • View a list of all uploaded files
  • Download files
  • Search for files by name
  • Delete files
  • Responsive web interface
  • RESTful API for programmatic access

Technologies Used

  • Java 17
  • Spring Boot
  • Spring Data JPA
  • Thymeleaf for server-side templating
  • Bootstrap 5 for responsive UI
  • H2 Database (can be configured for other databases)
  • Maven for dependency management

Setup and Installation

Prerequisites

  • Java 17 or higher
  • Maven

Steps

  1. Clone the repository:

    git clone https://github.com/yourusername/filemanagement.git
    cd filemanagement
    
  2. Configure the application:

    Edit src/main/resources/application.properties to set your preferred configuration:

    # File storage location (create this directory or change to your preferred location)
    file.upload-dir=./uploads
    
    # Database configuration (default is H2 in-memory database)
    spring.datasource.url=jdbc:h2:mem:filedb
    spring.datasource.driverClassName=org.h2.Driver
    spring.datasource.username=sa
    spring.datasource.password=password
    spring.jpa.database-platform=org.hibernate.dialect.H2Dialect
    
    # Enable H2 console (optional, for development)
    spring.h2.console.enabled=true
    spring.h2.console.path=/h2-console
    
    # Maximum file size
    spring.servlet.multipart.max-file-size=10MB
    spring.servlet.multipart.max-request-size=10MB
  3. Build the project:

    mvn clean install
    
  4. Run the application:

    mvn spring-boot:run
    
  5. Access the application:

Usage

Web Interface

  1. Home Page: Navigate to http://localhost:8080 to see a list of all uploaded files.
  2. Upload Files: Click on the "Upload File" button to go to the upload page.
  3. Download Files: Click on the "Download" button next to any file to download it.

REST API

The application provides a RESTful API for programmatic access:

Upload a File

POST /api/v1/files/upload

Request:

  • Form-data:
    • file: The file to upload
    • description (optional): Description of the file

Response:

{
  "fileName": "627b9ee7-856a-4ce9-a799-1b03977ac368Armand-Njapou-Resume.pdf",
  "fileDownloadUri": "http://localhost:8080/api/v1/files/download/627b9ee7-856a-4ce9-a799-1b03977ac368Armand-Njapou-Resume.pdf",
  "fileType": "application/pdf",
  "size": 12345
}

Download a File

GET /api/v1/files/download/{fileName}

Response: The file as a downloadable resource.

Get All Files

GET /api/v1/files/all

Response:

[
  {
    "id": 1,
    "fileName": "627b9ee7-856a-4ce9-a799-1b03977ac368Resume.pdf",
    "originalFileName": "Resume.pdf",
    "fileType": "application/pdf",
    "fileSize": "12345",
    "filePath": "/path/to/file",
    "description": "My resume",
    "uploadTime": "2023-05-20T15:30:45"
  }
]

Search Files

GET /api/v1/files/search/{fileName}

Response: List of files matching the search criteria.

Delete a File

DELETE /api/v1/files/{id}

Response: No content (204) if successful.

Project Structure

src/main/java/com/cwa/filemanagement/
β”œβ”€β”€ config/                  # Configuration classes
β”‚   └── FileStorageProperties.java
β”œβ”€β”€ controller/              # Web and API controllers
β”‚   β”œβ”€β”€ FileController.java  # REST API endpoints
β”‚   └── WebController.java   # Web interface controllers
β”œβ”€β”€ dto/                     # Data Transfer Objects
β”‚   β”œβ”€β”€ ApiResponse.java
β”‚   └── FileUploadResponse.java
β”œβ”€β”€ entity/                  # JPA entities
β”‚   └── FileEntity.java
β”œβ”€β”€ exception/               # Custom exceptions
β”‚   β”œβ”€β”€ FileNotFoundException.java
β”‚   β”œβ”€β”€ FileStorageException.java
β”‚   └── GlobalExceptionHandler.java
β”œβ”€β”€ repository/              # Data access layer
β”‚   └── FileRepository.java
β”œβ”€β”€ service/                 # Business logic
β”‚   β”œβ”€β”€ FileService.java     # Service interface
β”‚   └── impl/
β”‚       └── FileServiceImpl.java
└── FilemanagementApplication.java  # Main application class

src/main/resources/
β”œβ”€β”€ application.properties   # Application configuration
└── templates/               # Thymeleaf templates
    β”œβ”€β”€ index.html           # File listing page
    └── upload.html          # File upload page

License

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

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

About

No description, website, or topics provided.

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

No releases published

Packages

 
 
 

Contributors