diff --git a/sop-gateway/src/main/java/com/gitee/sop/gateway/interceptor/MyRouteInterceptor.java b/sop-gateway/src/main/java/com/gitee/sop/gateway/interceptor/MyRouteInterceptor.java index 9a017ce9..4ff60784 100644 --- a/sop-gateway/src/main/java/com/gitee/sop/gateway/interceptor/MyRouteInterceptor.java +++ b/sop-gateway/src/main/java/com/gitee/sop/gateway/interceptor/MyRouteInterceptor.java @@ -4,7 +4,6 @@ import com.gitee.sop.gatewaycommon.interceptor.RouteInterceptor; import com.gitee.sop.gatewaycommon.interceptor.RouteInterceptorContext; import com.gitee.sop.gatewaycommon.param.ApiParam; import lombok.extern.slf4j.Slf4j; -import org.springframework.cloud.client.ServiceInstance; import org.springframework.stereotype.Component; /** @@ -19,16 +18,16 @@ public class MyRouteInterceptor implements RouteInterceptor { @Override public void preRoute(RouteInterceptorContext context) { ApiParam apiParam = context.getApiParam(); - log.info("请求接口:{}, ip:{}", apiParam.fetchNameVersion(), apiParam.fetchIp()); + log.info("请求接口:{}, request_id:{}, app_id:{}, ip:{}", + apiParam.fetchNameVersion(), + apiParam.fetchRequestId(), + apiParam.fetchAppKey(), + apiParam.fetchIp() + ); } @Override public void afterRoute(RouteInterceptorContext context) { - ServiceInstance serviceInstance = context.getServiceInstance(); - log.info("请求成功,serviceId:{}({}:{}),微服务返回结果:{}", - serviceInstance.getServiceId(), - serviceInstance.getHost(),serviceInstance.getPort(), - context.getServiceResult()); } @Override diff --git a/sop-gateway/src/main/resources/META-INF/gateway.properties b/sop-gateway/src/main/resources/META-INF/gateway.properties index 99eca1a0..f4570497 100644 --- a/sop-gateway/src/main/resources/META-INF/gateway.properties +++ b/sop-gateway/src/main/resources/META-INF/gateway.properties @@ -3,6 +3,10 @@ spring.application.name=sop-gateway # 不用改,如果要改,请全局替换修改 sop.secret=MZZOUSTua6LzApIWXCwEgbBmxSzpzC +# 文件上传配置 +spring.servlet.multipart.enabled=true +spring.servlet.multipart.max-file-size=10MB + # 网关入口 sop.gateway-index-path=/ @@ -33,10 +37,3 @@ mybatis.mapper-locations=classpath:mybatis/mapper/*.xml mybatis.fill.com.gitee.fastmybatis.core.support.DateFillInsert=gmt_create mybatis.fill.com.gitee.fastmybatis.core.support.DateFillUpdate=gmt_modified -# POST请求最大缓存,默认是262144(256KB),即:256 * 1024 -# 如果需要传输大文本可以把值设置高一点 -spring.codec.max-in-memory-size=262144 - -# 文件上传配置 -spring.servlet.multipart.enabled=true -spring.servlet.multipart.max-file-size=10MB diff --git a/sop-gateway/src/main/resources/application-dev.properties b/sop-gateway/src/main/resources/application-dev.properties index 76a56288..28af61d7 100644 --- a/sop-gateway/src/main/resources/application-dev.properties +++ b/sop-gateway/src/main/resources/application-dev.properties @@ -9,4 +9,7 @@ mysql.password=root # nacos注册中心地址 register.url=127.0.0.1:8848 +# 上传文件最大容量,默认10MB +spring.servlet.multipart.max-file-size=10MB + logging.level.com.gitee=debug \ No newline at end of file diff --git a/sop-test/src/main/resources/large_img.png b/sop-test/src/main/resources/large_img.png new file mode 100644 index 00000000..9d708881 Binary files /dev/null and b/sop-test/src/main/resources/large_img.png differ diff --git a/sop-test/src/test/java/com/gitee/sop/test/AllInOneTest.java b/sop-test/src/test/java/com/gitee/sop/test/AllInOneTest.java index dca10c54..c8101f38 100644 --- a/sop-test/src/test/java/com/gitee/sop/test/AllInOneTest.java +++ b/sop-test/src/test/java/com/gitee/sop/test/AllInOneTest.java @@ -224,6 +224,29 @@ public class AllInOneTest extends TestBase { client.execute(requestBuilder); } + /** + * 演示大文件上传,先配置网关参数:spring.servlet.multipart.max-file-size=1MB + */ + public void testBigFile() { + Client client = new Client(url, appId, privateKey); + String root = System.getProperty("user.dir"); + Client.RequestBuilder requestBuilder = new Client.RequestBuilder() + .method("file.upload3") + .version("1.0") + .bizContent(new BizContent().add("remark", "test file upload")) + // 添加文件 + .addFile("image", new File(root + "/src/main/resources/large_img.png")) + .callback((requestInfo, responseData) -> { + System.out.println(responseData); + JSONObject jsonObject = JSON.parseObject(responseData); + JSONObject data = jsonObject.getJSONObject(requestInfo.getDataNode()); + Assert.assertEquals(data.getString("sub_code"), "isv.invalid-file-size"); + }) + ; + + client.execute(requestBuilder); + } + /** * 传递header */