This is an automated email from the ASF dual-hosted git repository.
zhangzicheng pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/shenyu.git
The following commit(s) were added to refs/heads/master by this push:
new 1c2c3dac6 [ISSUE #3740] add upload file example (#3768)
1c2c3dac6 is described below
commit 1c2c3dac6727b5567593ea7287d6043433983f03
Author: zhengpeng <[email protected]>
AuthorDate: Fri Jul 29 18:22:05 2022 +0800
[ISSUE #3740] add upload file example (#3768)
* feature: #issues 3740 http and mvc example
* feature: #3740 integrated test
* feature: #3740 integrated test use Logger to replace e.printStackTrace()
---
.../src/main/resources/1.txt | 1 +
.../src/main/resources/2.txt | 1 +
.../src/main/http/http-test-api-local.http | 35 +++++-
.../src/main/http/http-test-api.http | 35 +++++-
.../examples/http/controller/UploadController.java | 58 ++++++++++
.../src/main/resources/application.yml | 8 ++
.../src/main/http/http-test-api-local.http | 35 ++++++
.../src/main/http/http-test-api.http | 36 ++++++
.../springmvc/controller/UploadController.java | 57 ++++++++++
.../src/main/resources/application.properties | 5 +-
.../src/main/http/http-test-api-local.http | 123 +++++++++++++++++++++
.../src/main/http/http-test-api.http | 36 ++++++
.../springmvc/controller/UploadController.java | 56 ++++++++++
.../src/main/resources/application.yml | 8 +-
.../integrated/test/http/UploadControllerTest.java | 103 +++++++++++++++++
15 files changed, 593 insertions(+), 4 deletions(-)
diff --git a/shenyu-examples/shenyu-examples-common/src/main/resources/1.txt
b/shenyu-examples/shenyu-examples-common/src/main/resources/1.txt
new file mode 100644
index 000000000..9d07aa0df
--- /dev/null
+++ b/shenyu-examples/shenyu-examples-common/src/main/resources/1.txt
@@ -0,0 +1 @@
+111
\ No newline at end of file
diff --git a/shenyu-examples/shenyu-examples-common/src/main/resources/2.txt
b/shenyu-examples/shenyu-examples-common/src/main/resources/2.txt
new file mode 100644
index 000000000..6dd90d24d
--- /dev/null
+++ b/shenyu-examples/shenyu-examples-common/src/main/resources/2.txt
@@ -0,0 +1 @@
+222
\ No newline at end of file
diff --git
a/shenyu-examples/shenyu-examples-http/src/main/http/http-test-api-local.http
b/shenyu-examples/shenyu-examples-http/src/main/http/http-test-api-local.http
index 6acec079e..c4fa2fc14 100644
---
a/shenyu-examples/shenyu-examples-http/src/main/http/http-test-api-local.http
+++
b/shenyu-examples/shenyu-examples-http/src/main/http/http-test-api-local.http
@@ -133,4 +133,37 @@ GET
http://localhost:8189/test/request/parameter/pass?requestParameter=test
Accept: application/json
Content-Type: application/json
-###
+
+### example webFluxSingle
+POST http://localhost:8189/upload/webFluxSingle
+Cache-Control: no-cache
+Content-Type: multipart/form-data; boundary=WebAppBoundary
+
+--WebAppBoundary
+Content-Disposition: form-data; name="file"; filename="1.txt"
+Content-Type: multipart/form-data
+# you need to change your local path
+<
/Users/Code/shenyu/shenyu-examples/shenyu-examples-common/src/main/resources/1.txt
+
+--WebAppBoundary--
+
+### example webFluxFiles
+POST http://localhost:8189/upload/webFluxFiles
+Cache-Control: no-cache
+Content-Type: multipart/form-data; boundary=WebAppBoundary
+
+--WebAppBoundary
+Content-Disposition: form-data; name="files"; filename="1.txt";
+Content-Type: multipart/form-data
+# you need to change your local path
+<
/Users/Code/shenyu/shenyu-examples/shenyu-examples-common/src/main/resources/1.txt
+
+--WebAppBoundary--
+
+--WebAppBoundary
+Content-Disposition: form-data; name="files"; filename="2.txt";
+Content-Type: multipart/form-data
+# you need to change your local path
+<
/Users/Code/shenyu/shenyu-examples/shenyu-examples-common/src/main/resources/2.txt
+
+--WebAppBoundary--
\ No newline at end of file
diff --git
a/shenyu-examples/shenyu-examples-http/src/main/http/http-test-api.http
b/shenyu-examples/shenyu-examples-http/src/main/http/http-test-api.http
index d62ca06b8..fcafa8d17 100644
--- a/shenyu-examples/shenyu-examples-http/src/main/http/http-test-api.http
+++ b/shenyu-examples/shenyu-examples-http/src/main/http/http-test-api.http
@@ -177,4 +177,37 @@ GET
http://localhost:9195/http/test/request/parameter/pass?requestParameter=test
Accept: application/json
Content-Type: application/json
-###
+
+### shengyu getway proxy example webFluxSingle
+POST http://localhost:9195/http/upload/webFluxSingle
+Cache-Control: no-cache
+Content-Type: multipart/form-data; boundary=WebAppBoundary
+
+--WebAppBoundary
+Content-Disposition: form-data; name="file"; filename="1.txt"
+Content-Type: multipart/form-data
+# you need to change your local path
+<
/Users/Code/shenyu/shenyu-examples/shenyu-examples-common/src/main/resources/1.txt
+
+--WebAppBoundary--
+
+### shengyu getway proxy example webFluxFiles
+POST http://localhost:9195/http/upload/webFluxFiles
+Cache-Control: no-cache
+Content-Type: multipart/form-data; boundary=WebAppBoundary
+
+--WebAppBoundary
+Content-Disposition: form-data; name="files"; filename="1.txt";
+Content-Type: multipart/form-data
+# you need to change your local path
+<
/Users/Code/shenyu/shenyu-examples/shenyu-examples-common/src/main/resources/1.txt
+
+--WebAppBoundary--
+
+--WebAppBoundary
+Content-Disposition: form-data; name="files"; filename="2.txt";
+Content-Type: multipart/form-data
+# you need to change your local path
+<
/Users/Code/shenyu/shenyu-examples/shenyu-examples-common/src/main/resources/2.txt
+
+--WebAppBoundary--
diff --git
a/shenyu-examples/shenyu-examples-http/src/main/java/org/apache/shenyu/examples/http/controller/UploadController.java
b/shenyu-examples/shenyu-examples-http/src/main/java/org/apache/shenyu/examples/http/controller/UploadController.java
new file mode 100644
index 000000000..3ef9659b3
--- /dev/null
+++
b/shenyu-examples/shenyu-examples-http/src/main/java/org/apache/shenyu/examples/http/controller/UploadController.java
@@ -0,0 +1,58 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.shenyu.examples.http.controller;
+
+import org.apache.shenyu.client.springmvc.annotation.ShenyuSpringMvcClient;
+import org.springframework.http.MediaType;
+import org.springframework.http.codec.multipart.FilePart;
+import org.springframework.web.bind.annotation.*;
+import org.springframework.web.multipart.MultipartFile;
+import reactor.core.publisher.Flux;
+import reactor.core.publisher.Mono;
+
+import java.util.Arrays;
+import java.util.stream.Collectors;
+
+/**
+ * UploadController.
+ */
+@RestController
+@RequestMapping("/upload")
+@ShenyuSpringMvcClient("/upload/**")
+public class UploadController {
+
+ /**
+ * webFlux uploadFile
+ * @param file
+ * @return
+ */
+ @PostMapping(value = "/webFluxSingle", consumes =
{MediaType.MULTIPART_FORM_DATA_VALUE,MediaType.TEXT_PLAIN_VALUE})
+ public Mono<String> webFluxSingle(@RequestPart("file") FilePart file){
+ return Mono.just(file.filename());
+ }
+
+ /**
+ * webFlux uploadFiles
+ * @param files
+ * @return
+ */
+ @PostMapping(value = "/webFluxFiles", consumes =
{MediaType.MULTIPART_FORM_DATA_VALUE,MediaType.TEXT_PLAIN_VALUE})
+ public Mono<String> webFluxFiles(@RequestPart(value = "files", required =
false) Flux<FilePart> files){
+ return files.map(FilePart::filename).collect(Collectors.joining(","));
+ }
+}
diff --git
a/shenyu-examples/shenyu-examples-http/src/main/resources/application.yml
b/shenyu-examples/shenyu-examples-http/src/main/resources/application.yml
index 4762c9f72..e73cfb7c3 100644
--- a/shenyu-examples/shenyu-examples-http/src/main/resources/application.yml
+++ b/shenyu-examples/shenyu-examples-http/src/main/resources/application.yml
@@ -16,6 +16,8 @@
server:
port: 8189
address: 0.0.0.0
+ tomcat:
+ max-http-form-post-size: 100MB
shenyu:
register:
@@ -31,6 +33,12 @@ shenyu:
appName: http
# port: 8189
+spring:
+ servlet:
+ multipart:
+ max-file-size: 100MB
+ max-request-size: 100MB
+
logging:
level:
root: info
diff --git
a/shenyu-examples/shenyu-examples-springmvc-tomcat/src/main/http/http-test-api-local.http
b/shenyu-examples/shenyu-examples-springmvc-tomcat/src/main/http/http-test-api-local.http
index 31a9dac0e..4a81b9ae9 100644
---
a/shenyu-examples/shenyu-examples-springmvc-tomcat/src/main/http/http-test-api-local.http
+++
b/shenyu-examples/shenyu-examples-springmvc-tomcat/src/main/http/http-test-api-local.http
@@ -85,3 +85,38 @@ Content-Type: application/json
GET http://localhost:8290/test/request/parameter/pass?requestParameter=test
Accept: application/json
Content-Type: application/json
+
+### example singleFile
+POST http://localhost:8290/upload/singleFile
+Cache-Control: no-cache
+Content-Type: multipart/form-data; boundary=WebAppBoundary
+
+--WebAppBoundary
+Content-Disposition: form-data; name="file"; filename="1.txt"
+Content-Type: multipart/form-data
+# you need to change your local path
+<
/Users/Code/shenyu/shenyu-examples/shenyu-examples-common/src/main/resources/1.txt
+
+--WebAppBoundary--
+
+
+### example files
+POST http://localhost:8290/upload/files
+Cache-Control: no-cache
+Content-Type: multipart/form-data; boundary=WebAppBoundary
+
+--WebAppBoundary
+Content-Disposition: form-data; name="files"; filename="1.txt";
+Content-Type: multipart/form-data
+# you need to change your local path
+<
/Users/Code/shenyu/shenyu-examples/shenyu-examples-common/src/main/resources/1.txt
+
+--WebAppBoundary--
+
+--WebAppBoundary
+Content-Disposition: form-data; name="files"; filename="2.txt";
+Content-Type: multipart/form-data
+# you need to change your local path
+<
/Users/Code/shenyu/shenyu-examples/shenyu-examples-common/src/main/resources/2.txt
+
+--WebAppBoundary--
\ No newline at end of file
diff --git
a/shenyu-examples/shenyu-examples-springmvc-tomcat/src/main/http/http-test-api.http
b/shenyu-examples/shenyu-examples-springmvc-tomcat/src/main/http/http-test-api.http
index 0e2fc682d..0acba490d 100644
---
a/shenyu-examples/shenyu-examples-springmvc-tomcat/src/main/http/http-test-api.http
+++
b/shenyu-examples/shenyu-examples-springmvc-tomcat/src/main/http/http-test-api.http
@@ -85,3 +85,39 @@ Content-Type: application/json
GET
http://localhost:9195/springmvc/test/request/parameter/pass?requestParameter=test
Accept: application/json
Content-Type: application/json
+
+
+### shengyu getway prox example singleFile
+POST http://localhost:9195/springmvc/upload/singleFile
+Cache-Control: no-cache
+Content-Type: multipart/form-data; boundary=WebAppBoundary
+
+--WebAppBoundary
+Content-Disposition: form-data; name="file"; filename="1.txt"
+Content-Type: multipart/form-data
+# you need to change your local path
+<
/Users/Code/shenyu/shenyu-examples/shenyu-examples-common/src/main/resources/1.txt
+
+--WebAppBoundary--
+
+
+### shengyu getway prox example files
+POST http://localhost:9195/springmvc/upload/files
+Cache-Control: no-cache
+Content-Type: multipart/form-data; boundary=WebAppBoundary
+
+--WebAppBoundary
+Content-Disposition: form-data; name="files"; filename="1.txt";
+Content-Type: multipart/form-data
+# you need to change your local path
+<
/Users/Code/shenyu/shenyu-examples/shenyu-examples-common/src/main/resources/1.txt
+
+--WebAppBoundary--
+
+--WebAppBoundary
+Content-Disposition: form-data; name="files"; filename="2.txt";
+Content-Type: multipart/form-data
+# you need to change your local path
+<
/Users/Code/shenyu/shenyu-examples/shenyu-examples-common/src/main/resources/2.txt
+
+--WebAppBoundary--
\ No newline at end of file
diff --git
a/shenyu-examples/shenyu-examples-springmvc-tomcat/src/main/java/org/apache/shenyu/examples/springmvc/controller/UploadController.java
b/shenyu-examples/shenyu-examples-springmvc-tomcat/src/main/java/org/apache/shenyu/examples/springmvc/controller/UploadController.java
new file mode 100644
index 000000000..b206834c0
--- /dev/null
+++
b/shenyu-examples/shenyu-examples-springmvc-tomcat/src/main/java/org/apache/shenyu/examples/springmvc/controller/UploadController.java
@@ -0,0 +1,57 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.shenyu.examples.springmvc.controller;
+
+import org.apache.shenyu.client.springmvc.annotation.ShenyuSpringMvcClient;
+import org.springframework.web.bind.annotation.PostMapping;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RequestParam;
+import org.springframework.web.bind.annotation.RestController;
+import org.springframework.web.multipart.MultipartFile;
+
+import java.util.Arrays;
+import java.util.stream.Collectors;
+
+/**
+ * UploadController.
+ */
+@RestController
+@RequestMapping("/upload")
+@ShenyuSpringMvcClient("/upload/**")
+public class UploadController {
+
+ /**
+ * mvc uploadFile
+ * @param file
+ * @return
+ */
+ @PostMapping(value = "/singleFile")
+ public String singleFile(@RequestParam("file") final MultipartFile file) {
+ return file.getOriginalFilename();
+ }
+
+ /**
+ * mvc uploadFiles
+ * @param files
+ * @return
+ */
+ @PostMapping(value = "/files")
+ public String files(@RequestParam("files") final MultipartFile[] files) {
+ return
Arrays.stream(files).map(MultipartFile::getOriginalFilename).collect(Collectors.joining(","));
+ }
+}
diff --git
a/shenyu-examples/shenyu-examples-springmvc-tomcat/src/main/resources/application.properties
b/shenyu-examples/shenyu-examples-springmvc-tomcat/src/main/resources/application.properties
index cc95b347b..858afe6dd 100644
---
a/shenyu-examples/shenyu-examples-springmvc-tomcat/src/main/resources/application.properties
+++
b/shenyu-examples/shenyu-examples-springmvc-tomcat/src/main/resources/application.properties
@@ -16,4 +16,7 @@
server.port=8290
server.address=0.0.0.0
server.servlet.context-path=/
-spring.main.allow-bean-definition-overriding=true
\ No newline at end of file
+server.tomcat.max-swallow-size=100MB
+spring.main.allow-bean-definition-overriding=true
+spring.servlet.multipart.max-file-size=100MB
+spring.servlet.multipart.max-request-size=100MB
diff --git
a/shenyu-examples/shenyu-examples-springmvc/src/main/http/http-test-api-local.http
b/shenyu-examples/shenyu-examples-springmvc/src/main/http/http-test-api-local.http
new file mode 100644
index 000000000..fbe940811
--- /dev/null
+++
b/shenyu-examples/shenyu-examples-springmvc/src/main/http/http-test-api-local.http
@@ -0,0 +1,123 @@
+#
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements. See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+### orderSave
+POST http://localhost:8289/order/save
+Accept: application/json
+Content-Type: application/json
+
+{
+ "id": 123,
+ "name": "order"
+}
+
+### findById
+GET http://localhost:8289/order/findById?id=123
+Accept: application/json
+Content-Type: application/json
+
+### path
+GET http://localhost:8289/order/path/123/hahah
+Accept: application/json
+Content-Type: application/json
+
+### path
+GET http://localhost:8289/order/path/123/name
+Accept: application/json
+Content-Type: application/json
+
+### oauth2
+GET http://localhost:8289/order/oauth2/test
+Accept: application/json
+Content-Type: application/json
+Authorization:AuthorizationContext
+
+### payment
+POST http://localhost:8289/test/payment
+Accept: application/json
+Content-Type: application/json
+
+{
+ "userId": 123,
+ "userName": "name"
+}
+
+### findByUserId
+GET http://localhost:8289/test/findByUserId?userId=123
+Accept: application/json
+Content-Type: application/json
+
+### path
+GET http://localhost:8289/test/path/123?name=haha
+Accept: application/json
+Content-Type: application/json
+
+### path
+GET http://localhost:8289/test/path/123/name
+Accept: application/json
+Content-Type: application/json
+
+### waf pass
+POST http://localhost:8289/test/waf/pass
+Accept: application/json
+Content-Type: application/json
+
+### waf deny
+POST http://localhost:8289/test/waf/deny
+Accept: application/json
+Content-Type: application/json
+
+### request parameter pass
+GET http://localhost:8289/test/request/parameter/pass?requestParameter=test
+Accept: application/json
+Content-Type: application/json
+
+
+### example singleFile
+POST http://localhost:8289/upload/singleFile
+Cache-Control: no-cache
+Content-Type: multipart/form-data; boundary=WebAppBoundary
+
+--WebAppBoundary
+Content-Disposition: form-data; name="file"; filename="1.txt"
+Content-Type: multipart/form-data
+# you need to change your local path
+<
/Users/Code/shenyu/shenyu-examples/shenyu-examples-common/src/main/resources/1.txt
+
+--WebAppBoundary--
+
+
+### example files
+POST http://localhost:8289/upload/files
+Cache-Control: no-cache
+Content-Type: multipart/form-data; boundary=WebAppBoundary
+
+--WebAppBoundary
+Content-Disposition: form-data; name="files"; filename="1.txt";
+Content-Type: multipart/form-data
+# you need to change your local path
+<
/Users/Code/shenyu/shenyu-examples/shenyu-examples-common/src/main/resources/1.txt
+
+--WebAppBoundary--
+
+--WebAppBoundary
+Content-Disposition: form-data; name="files"; filename="2.txt";
+Content-Type: multipart/form-data
+# you need to change your local path
+<
/Users/Code/shenyu/shenyu-examples/shenyu-examples-common/src/main/resources/2.txt
+
+--WebAppBoundary--
\ No newline at end of file
diff --git
a/shenyu-examples/shenyu-examples-springmvc/src/main/http/http-test-api.http
b/shenyu-examples/shenyu-examples-springmvc/src/main/http/http-test-api.http
index 680922a0f..e36f006a4 100644
--- a/shenyu-examples/shenyu-examples-springmvc/src/main/http/http-test-api.http
+++ b/shenyu-examples/shenyu-examples-springmvc/src/main/http/http-test-api.http
@@ -85,3 +85,39 @@ Content-Type: application/json
GET http://localhost:9195/mvc/test/request/parameter/pass?requestParameter=test
Accept: application/json
Content-Type: application/json
+
+
+### shengyu getway proxy example singleFile
+POST http://localhost:9195/mvc/upload/singleFile
+Cache-Control: no-cache
+Content-Type: multipart/form-data; boundary=WebAppBoundary
+
+--WebAppBoundary
+Content-Disposition: form-data; name="file"; filename="1.txt"
+Content-Type: multipart/form-data
+# you need to change your local path
+<
/Users/Code/shenyu/shenyu-examples/shenyu-examples-common/src/main/resources/1.txt
+
+--WebAppBoundary--
+
+
+### shengyu getway proxy example files
+POST http://localhost:9195/mvc/upload/files
+Cache-Control: no-cache
+Content-Type: multipart/form-data; boundary=WebAppBoundary
+
+--WebAppBoundary
+Content-Disposition: form-data; name="files"; filename="1.txt";
+Content-Type: multipart/form-data
+# you need to change your local path
+<
/Users/Code/shenyu/shenyu-examples/shenyu-examples-common/src/main/resources/1.txt
+
+--WebAppBoundary--
+
+--WebAppBoundary
+Content-Disposition: form-data; name="files"; filename="2.txt";
+Content-Type: multipart/form-data
+# you need to change your local path
+<
/Users/Code/shenyu/shenyu-examples/shenyu-examples-common/src/main/resources/2.txt
+
+--WebAppBoundary--
\ No newline at end of file
diff --git
a/shenyu-examples/shenyu-examples-springmvc/src/main/java/org/apache/shenyu/examples/springmvc/controller/UploadController.java
b/shenyu-examples/shenyu-examples-springmvc/src/main/java/org/apache/shenyu/examples/springmvc/controller/UploadController.java
new file mode 100644
index 000000000..ddc94cc74
--- /dev/null
+++
b/shenyu-examples/shenyu-examples-springmvc/src/main/java/org/apache/shenyu/examples/springmvc/controller/UploadController.java
@@ -0,0 +1,56 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.shenyu.examples.springmvc.controller;
+
+import org.apache.shenyu.client.springmvc.annotation.ShenyuSpringMvcClient;
+import org.springframework.web.bind.annotation.PostMapping;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RequestParam;
+import org.springframework.web.bind.annotation.RestController;
+import org.springframework.web.multipart.MultipartFile;
+import java.util.Arrays;
+import java.util.stream.Collectors;
+
+/**
+ * UploadController.
+ */
+@RestController
+@RequestMapping("/upload")
+@ShenyuSpringMvcClient("/upload/**")
+public class UploadController {
+
+ /**
+ * mvc uploadFile
+ * @param file
+ * @return
+ */
+ @PostMapping(value = "/singleFile")
+ public String singleFile(@RequestParam("file") final MultipartFile file) {
+ return file.getOriginalFilename();
+ }
+
+ /**
+ * mvc uploadFiles
+ * @param files
+ * @return
+ */
+ @PostMapping(value = "/files")
+ public String files(@RequestParam("files") final MultipartFile[] files) {
+ return
Arrays.stream(files).map(MultipartFile::getOriginalFilename).collect(Collectors.joining(","));
+ }
+}
diff --git
a/shenyu-examples/shenyu-examples-springmvc/src/main/resources/application.yml
b/shenyu-examples/shenyu-examples-springmvc/src/main/resources/application.yml
index b3de9cb2d..9fb5a6a08 100644
---
a/shenyu-examples/shenyu-examples-springmvc/src/main/resources/application.yml
+++
b/shenyu-examples/shenyu-examples-springmvc/src/main/resources/application.yml
@@ -18,6 +18,12 @@ server:
address: 0.0.0.0
servlet:
context-path: /
+ tomcat:
+ max-http-form-post-size: 100MB
spring:
main:
- allow-bean-definition-overriding: true
\ No newline at end of file
+ allow-bean-definition-overriding: true
+ servlet:
+ multipart:
+ max-file-size: 100MB
+ max-request-size: 100MB
\ No newline at end of file
diff --git
a/shenyu-integrated-test/shenyu-integrated-test-http/src/test/java/org/apache/shenyu/integrated/test/http/UploadControllerTest.java
b/shenyu-integrated-test/shenyu-integrated-test-http/src/test/java/org/apache/shenyu/integrated/test/http/UploadControllerTest.java
new file mode 100644
index 000000000..ac1113a8c
--- /dev/null
+++
b/shenyu-integrated-test/shenyu-integrated-test-http/src/test/java/org/apache/shenyu/integrated/test/http/UploadControllerTest.java
@@ -0,0 +1,103 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.shenyu.integrated.test.http;
+
+import okhttp3.MediaType;
+import okhttp3.MultipartBody;
+import okhttp3.RequestBody;
+import org.apache.shenyu.integratedtest.common.helper.HttpHelper;
+import org.junit.jupiter.api.AfterAll;
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.Test;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import java.io.BufferedWriter;
+import java.io.File;
+import java.io.IOException;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.Paths;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+
+public class UploadControllerTest {
+
+ private static final String FILE_PATH_NOE = "1.txt";
+
+ private static final String FILE_PATH_TWO = "2.txt";
+
+ private static final Logger LOG =
LoggerFactory.getLogger(UploadControllerTest.class);
+
+ @BeforeAll
+ public static void setup() throws IOException {
+ Path pathOne = Paths.get(FILE_PATH_NOE);
+ Path pathTwo = Paths.get(FILE_PATH_TWO);
+ if (!Files.exists(pathOne)) {
+ Files.createFile(pathOne);
+ }
+ if (!Files.exists(pathTwo)) {
+ Files.createFile(pathTwo);
+ }
+ try {
+ BufferedWriter bufferedWriterOne =
Files.newBufferedWriter(pathOne);
+ bufferedWriterOne.write("111");
+ bufferedWriterOne.flush();
+ bufferedWriterOne.close();
+ BufferedWriter bufferedWriterTwo =
Files.newBufferedWriter(pathTwo);
+ bufferedWriterTwo.write("222");
+ bufferedWriterTwo.flush();
+ bufferedWriterTwo.close();
+ } catch (IOException e) {
+ LOG.error("write file fail", e);
+ }
+ }
+
+ @Test
+ public void testWebFluxSingle() throws IOException {
+ File fileOne = new File(FILE_PATH_NOE);
+ RequestBody fileBodyOne =
RequestBody.create(MediaType.parse("multipart/form-data"), fileOne);
+ MultipartBody requestBody = new MultipartBody.Builder()
+ .setType(MultipartBody.FORM)
+ .addFormDataPart("file", FILE_PATH_NOE, fileBodyOne)
+ .build();
+ final String response =
HttpHelper.INSTANCE.postGateway("/http/upload/webFluxSingle", requestBody,
String.class);
+ assertEquals(response, FILE_PATH_NOE);
+ }
+
+ @Test
+ public void testWebFluxFiles() throws IOException {
+ File fileOne = new File(FILE_PATH_NOE);
+ File fileTwo = new File(FILE_PATH_TWO);
+ RequestBody fileBodyOne =
RequestBody.create(MediaType.parse("multipart/form-data"), fileOne);
+ RequestBody fileBodyTwo =
RequestBody.create(MediaType.parse("multipart/form-data"), fileTwo);
+ MultipartBody requestBody = new MultipartBody.Builder()
+ .setType(MultipartBody.FORM)
+ .addFormDataPart("files", FILE_PATH_NOE, fileBodyOne)
+ .addFormDataPart("files", FILE_PATH_TWO, fileBodyTwo)
+ .build();
+ final String response =
HttpHelper.INSTANCE.postGateway("/http/upload/webFluxFiles", requestBody,
String.class);
+ assertEquals(response, FILE_PATH_NOE + "," + FILE_PATH_TWO);
+ }
+
+ @AfterAll
+ public static void clean() throws IOException {
+ Files.delete(Paths.get(FILE_PATH_NOE));
+ Files.delete(Paths.get(FILE_PATH_TWO));
+ }
+
+}