backend/resource-service/README.md
Resource Service is a resource management service built on Spring Boot 3.2.4, specifically designed for handling file upload, download, storage and management. The service integrates S3-compatible object storage (MinIO), MySQL database, Redis caching and other infrastructure, providing complete file lifecycle management functionality.
/file/upload)/file/upload-video)/file/share-file-upload)/file/download)| Component | Technology | Version Requirement |
|---|---|---|
| Backend Framework | Spring Boot | 3.2.4 |
| Java | Java | 21 |
| Database | MySQL + MyBatis-Plus | 8.0.28 / 3.5.5 |
| Object Storage | AWS S3 SDK | 2.17.102 |
| Connection Pool | Druid | 1.2.16 |
| Cache | Redis | - |
| Build Tool | Maven | 3.6+ |
| Containerization | Docker | - |
| Logging Framework | Logback | - |
resource-service/
โโโ src/main/java/com/iflytek/rpa/resource/
โ โโโ ResourceApplication.java # Spring Boot application startup class
โ โโโ common/ # Common components
โ โ โโโ exp/ # Exception handling
โ โ โ โโโ GlobalExceptionHandler.java
โ โ โ โโโ ServiceException.java
โ โ โโโ response/ # Response encapsulation
โ โ โโโ AppResponse.java
โ โ โโโ ErrorCodeEnum.java
โ โโโ file/ # File management module
โ โโโ config/ # Configuration classes
โ โ โโโ S3Config.java # S3 storage configuration
โ โโโ controller/ # Controllers
โ โ โโโ FileController.java # File operation controller
โ โโโ dao/ # Data access layer
โ โ โโโ FileMapper.java
โ โ โโโ FileMapper.xml
โ โโโ entity/ # Entity classes
โ โ โโโ enums/ # Enum classes
โ โ โ โโโ FileType.java
โ โ โโโ vo/ # View objects
โ โ โ โโโ ShareFileUploadVo.java
โ โ โโโ File.java # File entity
โ โโโ service/ # Service layer
โ โ โโโ impl/ # Service implementations
โ โ โ โโโ FileServiceImpl.java
โ โ โโโ FileService.java # File service interface
โ โโโ utils/ # Utility classes
โ โโโ IdWorker.java # ID generator
โโโ src/main/resources/
โ โโโ application.yml # Main configuration file
โ โโโ application-local.yml # Local environment configuration
โ โโโ logback-delayed.xml # Logging configuration
โโโ Dockerfile # Docker image build
โโโ pom.xml # Maven project configuration
โโโ README.md # Project documentation
git clone <repository-url>
cd resource-service
Create .env file and configure necessary environment variables:
# Database configuration
DATABASE_HOST=localhost
DATABASE_PORT=3306
DATABASE_NAME=resource_service
DATABASE_USERNAME=your_db_username
DATABASE_PASSWORD=your_db_password
# Redis configuration
REDIS_HOST=localhost
REDIS_PORT=6379
REDIS_DB=0
REDIS_PASSWORD=your_redis_password
# MinIO/S3 configuration
MINIO_URL=http://localhost:9000
MINIO_BUCKET=resource-bucket
MINIO_AK=your_access_key
MINIO_SK=your_secret_key
mvn clean package -DskipTests
java -jar target/resource-0.0.1-SNAPSHOT.jar --spring.profiles.active=local
Visit http://localhost:8030/api/resource to verify service startup.
docker build -t resource-service:latest .
docker run -d --name resource-service \
-p 8030:8030 \
-e DATABASE_HOST=your_db_host \
-e DATABASE_USERNAME=your_db_username \
-e DATABASE_PASSWORD=your_db_password \
-e REDIS_HOST=your_redis_host \
-e MINIO_URL=your_minio_url \
-e MINIO_AK=your_access_key \
-e MINIO_SK=your_secret_key \
resource-service:latest
POST /api/resource/file/upload
curl -X POST "http://localhost:8030/api/resource/file/upload" \
-H "Content-Type: multipart/form-data" \
-F "file=@/path/to/your/file.jpg"
Response Format:
{
"code": 200,
"message": "success",
"data": "file-uuid-12345"
}
POST /api/resource/file/upload-video
curl -X POST "http://localhost:8030/api/resource/file/upload-video" \
-H "Content-Type: multipart/form-data" \
-F "file=@/path/to/your/video.mp4"
POST /api/resource/file/share-file-upload
curl -X POST "http://localhost:8030/api/resource/file/share-file-upload" \
-H "Content-Type: multipart/form-data" \
-F "file=@/path/to/your/large-file.zip"
Response Format:
{
"code": 200,
"message": "success",
"data": {
"fileId": "file-uuid-12345",
"type": 1,
"filename": "large-file.zip"
}
}
GET /api/resource/file/download?fileId=file-uuid-12345
curl -X GET "http://localhost:8030/api/resource/file/download?fileId=file-uuid-12345" \
-o downloaded-file.jpg
| Configuration | Default Value | Description |
|---|---|---|
spring.servlet.multipart.max-file-size | 50MB | Maximum upload size for regular files |
spring.servlet.multipart.max-request-size | 110MB | Maximum request size |
spring.servlet.multipart.file-size-threshold | 100MB | File size threshold |
| Configuration | Description |
|---|---|
spring.datasource.url | MySQL connection URL |
spring.datasource.username | Database username |
spring.datasource.password | Database password |
spring.datasource.druid.* | Druid connection pool configuration |
| Configuration | Description |
|---|---|
amazonaws.s3.url | S3 service address |
amazonaws.s3.bucket | Bucket name |
amazonaws.s3.accessKey | Access key |
amazonaws.s3.secretKey | Secret key |
amazonaws.s3.maxConnections | Maximum connections |
# Run all tests
mvn test
# Run specific test class
mvn test -Dtest=FileServiceTest
# Compile check
mvn compile
# Code formatting
mvn spotless:apply
# Real-time view of application logs
tail -f logs/application.log
logging.level.*2024-01-01 10:30:15.123 INFO [http-nio-8030-exec-1] c.i.r.r.f.s.i.FileServiceImpl : File upload successful, file ID: file-uuid-12345
2024-01-01 10:30:16.456 INFO [http-nio-8030-exec-2] c.i.r.r.f.s.i.FileServiceImpl : File download successful, file ID: file-uuid-12345
A: Check the following points:
A: Modify the following configuration in application.yml:
spring:
servlet:
multipart:
max-file-size: 100MB
max-request-size: 150MB
A: You can monitor through:
A:
A:
This project is licensed under the MIT License. You are free to use, modify and distribute this code for both personal and commercial projects.