diff --git a/config/nacos/cn/firstleg-service.yml b/config/nacos/cn/firstleg-service.yml index 910720455..36a658d02 100644 --- a/config/nacos/cn/firstleg-service.yml +++ b/config/nacos/cn/firstleg-service.yml @@ -4,6 +4,10 @@ spring: username: ${FIRSTLEG_DB_USERNAME} password: ${FIRSTLEG_DB_PASSWORD} driver-class-name: com.mysql.cj.jdbc.Driver + servlet: + multipart: + max-file-size: ${FIRSTLEG_MULTIPART_MAX_FILE_SIZE:50MB} + max-request-size: ${FIRSTLEG_MULTIPART_MAX_REQUEST_SIZE:52MB} baiyue.clients.warehouse.url: ${WAREHOUSE_SERVICE_URL:} baiyue.clients.order.url: ${ORDER_SERVICE_URL:} baiyue.clients.file.url: ${FILE_SERVICE_URL:} diff --git a/config/nacos/local/firstleg-service.yml b/config/nacos/local/firstleg-service.yml index 1123e5927..b893c82b5 100644 --- a/config/nacos/local/firstleg-service.yml +++ b/config/nacos/local/firstleg-service.yml @@ -3,6 +3,8 @@ spring.datasource: url: ${FIRSTLEG_DB_URL:jdbc:mysql://127.0.0.1:3306/baiyue_firstleg?useUnicode=true&characterEncoding=utf8&serverTimezone=Asia/Shanghai&rewriteBatchedStatements=true} username: ${FIRSTLEG_DB_USERNAME:root} password: ${FIRSTLEG_DB_PASSWORD:123456} +spring.servlet.multipart.max-file-size: ${FIRSTLEG_MULTIPART_MAX_FILE_SIZE:50MB} +spring.servlet.multipart.max-request-size: ${FIRSTLEG_MULTIPART_MAX_REQUEST_SIZE:52MB} baiyue.clients.warehouse.url: ${WAREHOUSE_SERVICE_URL:} baiyue.clients.order.url: ${ORDER_SERVICE_URL:} baiyue.clients.file.url: ${FILE_SERVICE_URL:} diff --git a/firstleg/src/main/resources/application.yml b/firstleg/src/main/resources/application.yml index 1a5342f3a..e31ea3e38 100644 --- a/firstleg/src/main/resources/application.yml +++ b/firstleg/src/main/resources/application.yml @@ -22,8 +22,8 @@ spring: config.namespace: ${NACOS_NAMESPACE:public} servlet: multipart: - max-file-size: 5MB - max-request-size: 6MB + max-file-size: ${FIRSTLEG_MULTIPART_MAX_FILE_SIZE:50MB} + max-request-size: ${FIRSTLEG_MULTIPART_MAX_REQUEST_SIZE:52MB} baiyue: carrier-schedule: providers: diff --git a/firstleg/src/main/resources/openapi/customs-v1.yaml b/firstleg/src/main/resources/openapi/customs-v1.yaml index 2804db526..b168e1ec2 100644 --- a/firstleg/src/main/resources/openapi/customs-v1.yaml +++ b/firstleg/src/main/resources/openapi/customs-v1.yaml @@ -115,7 +115,7 @@ components: InboundIds: {name: inboundIds, in: query, required: true, schema: {type: array, minItems: 1, maxItems: 200, items: {$ref: '#/components/schemas/LongId'}}} requestBodies: ActionBody: {required: true, content: {application/json: {schema: {$ref: '#/components/schemas/ActionRequest'}}}} - FileBody: {required: true, content: {multipart/form-data: {schema: {type: object, required: [file], properties: {file: {type: string, format: binary, description: 任意格式且最大50MB}}}}}} + FileBody: {required: true, content: {multipart/form-data: {schema: {type: object, required: [file], properties: {file: {type: string, format: binary, description: 任意格式且最大50MB;multipart整请求上限52MB}}}}}} responses: ContainerResponse: {description: 成功或业务失败, content: {application/json: {schema: {$ref: '#/components/schemas/ContainerEnvelope'}}}} DocumentResponse: {description: 成功或业务失败, content: {application/json: {schema: {$ref: '#/components/schemas/DocumentEnvelope'}}}} diff --git a/firstleg/src/test/java/com/baiyue/firstleg/customs/container/ContainerCustomsMultipartConfigurationContractTest.java b/firstleg/src/test/java/com/baiyue/firstleg/customs/container/ContainerCustomsMultipartConfigurationContractTest.java new file mode 100644 index 000000000..ccbc57e4b --- /dev/null +++ b/firstleg/src/test/java/com/baiyue/firstleg/customs/container/ContainerCustomsMultipartConfigurationContractTest.java @@ -0,0 +1,35 @@ +package com.baiyue.firstleg.customs.container; + +import org.junit.jupiter.api.Test; + +import java.nio.charset.StandardCharsets; +import java.nio.file.Files; +import java.nio.file.Path; + +import static org.assertj.core.api.Assertions.assertThat; + +class ContainerCustomsMultipartConfigurationContractTest { + private static final String FILE_LIMIT = "${FIRSTLEG_MULTIPART_MAX_FILE_SIZE:50MB}"; + private static final String REQUEST_LIMIT = "${FIRSTLEG_MULTIPART_MAX_REQUEST_SIZE:52MB}"; + + @Test void applicationAndEnvironmentConfigsPermitFiftyMegabyteCustomsFiles() throws Exception { + assertLimits(read("firstleg/src/main/resources/application.yml")); + assertLimits(read("config/nacos/cn/firstleg-service.yml")); + assertLimits(read("config/nacos/local/firstleg-service.yml")); + } + + @Test void customsOpenApiPublishesFileAndMultipartRequestLimits() throws Exception { + assertThat(read("firstleg/src/main/resources/openapi/customs-v1.yaml")) + .contains("任意格式且最大50MB", "multipart整请求上限52MB"); + } + + private static void assertLimits(String yaml) { + assertThat(yaml).contains("max-file-size: " + FILE_LIMIT, "max-request-size: " + REQUEST_LIMIT); + } + + private static String read(String repositoryPath) throws Exception { + Path direct = Path.of(repositoryPath); + Path path = Files.exists(direct) ? direct : Path.of("..").resolve(repositoryPath).normalize(); + return Files.readString(path, StandardCharsets.UTF_8); + } +}