This project is a Spring Boot application that provides a RESTful API for storing, retrieving, and managing files. It supports storing files in both a database and the file system. The API includes endpoints for uploading files, retrieving files, and downloading files from the file system.
- Upload files to the database and file system.
- Retrieve all files with metadata (name, type, and access URL).
- Download files by name from the file system.
- Supports cross-origin requests.
- Java 17
- Spring Boot
- Spring Data JPA
- Hibernate
- MySQL or PostgreSQL
- Maven
- Lombok
- SLF4J for logging
- Java 17 or later installed
- Maven installed
- MySQL or PostgreSQL database setup
-
Clone the repository:
git clone https://github.com/Subhashchandra-Birajdar/UploadFile-image.git cd UploadFile-image
-
Configure the database:
Open the src/main/resources/application.properties (or application.yml) file and configure your database connection.
properties
spring.datasource.url=jdbc:postgresql://localhost:5432/your-database-name
spring.datasource.username=your-username
spring.datasource.password=your-password
spring.jpa.hibernate.ddl-auto=update
file.storage.path=C:\path\to\your\file\storage\directory\
The application will start on http://localhost:8080
- URL:
/api/uploadFilesIntoDB
- Method:
POST
- Description: Upload a file to the database and file system.
- Request:
file
(multipart/form-data): The file to be uploaded.
- Response:
200 OK
with a success message.
- URL:
/api/files
- Method:
GET
- Description: Retrieve a list of all files with their metadata.
- Response:
200 OK
with a list of files (name, type, URL).
- URL:
/api/getFilesFromFileSystem/{fileName}
- Method:
GET
- Description: Download a file from the file system by its name.
- Path Parameter:
fileName
: The name of the file to download.
- Response:
200 OK
with the file's binary data.
POST /api/uploadFilesIntoDB
Parameter | Type | Description |
---|---|---|
'file' | multipart/form-data |
Required. The file to be uploaded. |
GET /api/files
Parameter | Type | Description |
---|---|---|
'none' | string |
Required.Retrieves a list of all files with metadata. |
GET /api/getFilesFromFileSystem/{fileName}
Parameter | Type | Description |
---|---|---|
id |
string |
Required. image of name to fetch |
src/main/java/com/jts/entity/Files.java
: The entity class representing the files stored in the database.src/main/java/com/jts/repository/FileRepository.java
: The repository interface for accessing file data.src/main/java/com/jts/service/FilesService.java
: The service layer handling file operations.src/main/java/com/jts/controller/FilesController.java
: The REST controller exposing the API endpoints.
This project uses SLF4J with Logback for logging. Logs are written to the console during application execution.
The FilesController
and FilesService
classes include log statements to track the flow of operations.
If you'd like to contribute to this project, feel free to fork the repository and submit a pull request. Issues and feature requests are also welcome!