The File API is a RESTful service that allows users to upload, retrieve, and manage files. It provides endpoints for uploading files with metadata, retrieving file metadata and content, and deleting files.
- Upload files with associated metadata
- Retrieve file metadata and content by token
- Delete files by token
- Automatically remove expired files based on the expiration time
- Secure file storage using MinIO object storage
- Integration with MongoDB for storing file metadata
- Authentication using Basic Auth
- API documentation using Swagger
- Logging and exception handling
- Integration and unit tests using JUnit 5 and Mockito
- Distributed locking using Redis
- Kotlin
- Spring Boot
- Spring Data MongoDB
- Spring Security
- MinIO
- Swagger
- JUnit 5
- Mockito
- Testcontainers
- Redis
Before you begin, ensure your system meets the following requirements:
- Java: v21.0.2
- Maven: v3.9.5
- Docker: v25.0.3
- Docker Compose: v2.24.6
-
Clone the repository:
git clone https://github.com/ktenman/file-api.git
-
Navigate to the project directory:
cd file-api -
Build and run the project using Docker Compose:
docker-compose -f docker-compose.yml up
The application uses the following configuration properties:
spring.data.mongodb.uri: MongoDB connection URIminio.url: MinIO server URLminio.access-key: MinIO access keyminio.secret-key: MinIO secret keyminio.bucket-name: MinIO bucket name for storing files
You can modify these properties in the application.properties file located in src/main/resources.
The API documentation is available using Swagger. Once the application is running, you can access the Swagger UI at http://localhost:6011/docs or http://localhost:6011/swagger-ui/index.html
To run the unit and integration tests, use the following command:
mvn testThe File API uses Basic Authentication for securing the endpoints. The default username is admin and the password is
hunter2. You can modify the authentication credentials in the ApiAuthenticationProvider class.
POST /files: Upload a file with metadataGET /files: Retrieve file metadata by tokensGET /files/{token}/content: Download a file by tokenGET /files/{token}/meta: Retrieve file metadata by tokenDELETE /files/{token}: Delete a file by token
For detailed information about the request and response formats, please refer to the API documentation.
This README file provides an overview of the File API project, including its features, technologies used, installation instructions, configuration details, API documentation, and usage guidelines. The project aims to provide a simple and secure file management service with support for file uploads, retrieval, and guidelines. It also demonstrates the integration of various technologies and practices, such as Spring Boot, MongoDB, MinIO, Swagger, and Testcontainers.