diff --git a/changelog.md b/changelog.md index cfc42ddd..b645af4e 100644 --- a/changelog.md +++ b/changelog.md @@ -1,5 +1,9 @@ # changelog +## 3.1.2 + +- 修复图片上传保存后图片破损问题 + ## 3.1.1 - 修复继承WebMvcConfigurationSupport导致的jackson序列化时间问题 diff --git a/sop-auth/pom.xml b/sop-auth/pom.xml index d8be7c1f..e89b232d 100644 --- a/sop-auth/pom.xml +++ b/sop-auth/pom.xml @@ -26,7 +26,7 @@ com.gitee.sop sop-service-common - 3.1.1-SNAPSHOT + 3.1.2-SNAPSHOT diff --git a/sop-common/pom.xml b/sop-common/pom.xml index 89c70b7d..39a33e38 100644 --- a/sop-common/pom.xml +++ b/sop-common/pom.xml @@ -5,7 +5,7 @@ 4.0.0 com.gitee.sop sop-common - 3.1.1-SNAPSHOT + 3.1.2-SNAPSHOT pom diff --git a/sop-common/sop-bridge-gateway/pom.xml b/sop-common/sop-bridge-gateway/pom.xml index 078a0d9c..5c1465bd 100644 --- a/sop-common/sop-bridge-gateway/pom.xml +++ b/sop-common/sop-bridge-gateway/pom.xml @@ -5,11 +5,11 @@ sop-common com.gitee.sop - 3.1.1-SNAPSHOT + 3.1.2-SNAPSHOT ../pom.xml 4.0.0 - 3.1.1-SNAPSHOT + 3.1.2-SNAPSHOT sop-bridge-gateway @@ -17,7 +17,7 @@ com.gitee.sop sop-gateway-common - 3.1.1-SNAPSHOT + 3.1.2-SNAPSHOT diff --git a/sop-common/sop-bridge-zuul/pom.xml b/sop-common/sop-bridge-zuul/pom.xml index 4787ab59..efd0927e 100644 --- a/sop-common/sop-bridge-zuul/pom.xml +++ b/sop-common/sop-bridge-zuul/pom.xml @@ -5,11 +5,11 @@ sop-common com.gitee.sop - 3.1.1-SNAPSHOT + 3.1.2-SNAPSHOT ../pom.xml 4.0.0 - 3.1.1-SNAPSHOT + 3.1.2-SNAPSHOT sop-bridge-zuul @@ -17,7 +17,7 @@ com.gitee.sop sop-gateway-common - 3.1.1-SNAPSHOT + 3.1.2-SNAPSHOT diff --git a/sop-common/sop-gateway-common/pom.xml b/sop-common/sop-gateway-common/pom.xml index 5a1e11ca..bb26587d 100644 --- a/sop-common/sop-gateway-common/pom.xml +++ b/sop-common/sop-gateway-common/pom.xml @@ -5,11 +5,11 @@ com.gitee.sop sop-common - 3.1.1-SNAPSHOT + 3.1.2-SNAPSHOT ../pom.xml sop-gateway-common - 3.1.1-SNAPSHOT + 3.1.2-SNAPSHOT jar sop-gateway-common diff --git a/sop-common/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/gateway/filter/IndexFilter.java b/sop-common/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/gateway/filter/IndexFilter.java index eff18885..4e6f6654 100644 --- a/sop-common/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/gateway/filter/IndexFilter.java +++ b/sop-common/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/gateway/filter/IndexFilter.java @@ -80,15 +80,16 @@ public class IndexFilter implements WebFilter { if (request.getMethod() == HttpMethod.POST) { ServerRequest serverRequest = ServerWebExchangeUtil.createReadBodyRequest(exchange); // 读取请求体中的内容 - Mono modifiedBody = serverRequest.bodyToMono(String.class) - .flatMap(body -> { + Mono modifiedBody = serverRequest.bodyToMono(byte[].class) + .flatMap(data -> { + String body = new String(data, SopConstants.CHARSET_UTF8); // 构建ApiParam ApiParam apiParam = ServerWebExchangeUtil.getApiParam(exchange, body); // 签名验证 doValidate(exchange, apiParam); - return Mono.just(body); + return Mono.just(data); }); - BodyInserter bodyInserter = BodyInserters.fromPublisher(modifiedBody, (Class) String.class); + BodyInserter bodyInserter = BodyInserters.fromPublisher(modifiedBody, (Class)byte[].class); HttpHeaders headers = new HttpHeaders(); headers.putAll(exchange.getRequest().getHeaders()); @@ -130,7 +131,9 @@ public class IndexFilter implements WebFilter { validator.validate(apiParam); this.afterValidate(exchange, apiParam); } catch (ApiException e) { - log.error("验证失败,ip:{}, params:{}, errorMsg:{}", apiParam.fetchIp(), apiParam.toJSONString(), e.getMessage()); + log.error("验证失败,url:{}, ip:{}, params:{}, errorMsg:{}", + exchange.getRequest().getURI().toString(), + apiParam.fetchIp(), apiParam.toJSONString(), e.getMessage()); ServerWebExchangeUtil.setThrowable(exchange, e); } } diff --git a/sop-common/sop-service-common/pom.xml b/sop-common/sop-service-common/pom.xml index 7f6343dd..7aa25523 100644 --- a/sop-common/sop-service-common/pom.xml +++ b/sop-common/sop-service-common/pom.xml @@ -6,11 +6,11 @@ com.gitee.sop sop-common - 3.1.1-SNAPSHOT + 3.1.2-SNAPSHOT ../pom.xml sop-service-common - 3.1.1-SNAPSHOT + 3.1.2-SNAPSHOT jar sop-service-common diff --git a/sop-example/sop-book/sop-book-web/pom.xml b/sop-example/sop-book/sop-book-web/pom.xml index c25f1c4e..d56a1219 100644 --- a/sop-example/sop-book/sop-book-web/pom.xml +++ b/sop-example/sop-book/sop-book-web/pom.xml @@ -28,7 +28,7 @@ com.gitee.sop sop-service-common - 3.1.1-SNAPSHOT + 3.1.2-SNAPSHOT com.gitee.sop diff --git a/sop-example/sop-easyopen/pom.xml b/sop-example/sop-easyopen/pom.xml index 8fef3623..e874764d 100644 --- a/sop-example/sop-easyopen/pom.xml +++ b/sop-example/sop-easyopen/pom.xml @@ -29,7 +29,7 @@ com.gitee.sop sop-service-common - 3.1.1-SNAPSHOT + 3.1.2-SNAPSHOT diff --git a/sop-example/sop-story/sop-story-web/pom.xml b/sop-example/sop-story/sop-story-web/pom.xml index efde8f07..9a11a612 100644 --- a/sop-example/sop-story/sop-story-web/pom.xml +++ b/sop-example/sop-story/sop-story-web/pom.xml @@ -28,7 +28,7 @@ com.gitee.sop sop-service-common - 3.1.1-SNAPSHOT + 3.1.2-SNAPSHOT com.gitee.sop diff --git a/sop-example/sop-story/sop-story-web/src/main/java/com/gitee/sop/storyweb/controller/FileUploadDemoController.java b/sop-example/sop-story/sop-story-web/src/main/java/com/gitee/sop/storyweb/controller/FileUploadDemoController.java index e5854db1..e25608b9 100644 --- a/sop-example/sop-story/sop-story-web/src/main/java/com/gitee/sop/storyweb/controller/FileUploadDemoController.java +++ b/sop-example/sop-story/sop-story-web/src/main/java/com/gitee/sop/storyweb/controller/FileUploadDemoController.java @@ -14,8 +14,10 @@ import org.springframework.web.bind.annotation.RestController; import org.springframework.web.multipart.MultipartFile; import javax.servlet.http.HttpServletRequest; +import java.io.File; import java.io.IOException; import java.util.Collection; +import java.util.Optional; /** * 演示文件上传 @@ -70,6 +72,25 @@ public class FileUploadDemoController { return result; } + @ApiMapping(value = "demo.file.upload3") + public FileUploadResult file3(FileUploadParam2 param, HttpServletRequest request) { + System.out.println(param.getRemark()); + FileUploadResult result = new FileUploadResult(); + // 获取上传的文件 + Collection uploadFiles = UploadUtil.getUploadFiles(request); + Optional first = uploadFiles.stream().findFirst(); + if (first.isPresent()) { + MultipartFile multipartFile = first.get(); + try { + String path = System.getProperty("user.dir"); + multipartFile.transferTo(new File(path + "/img_"+System.currentTimeMillis()+".png")); + } catch (IOException e) { + e.printStackTrace(); + } + } + return result; + } + private FileUploadResult.FileMeta buildFileMeta(MultipartFile multipartFile) { // 文件名 String fileName = multipartFile.getOriginalFilename(); diff --git a/sop-gateway/pom.xml b/sop-gateway/pom.xml index 7dbb32ac..50042fbc 100644 --- a/sop-gateway/pom.xml +++ b/sop-gateway/pom.xml @@ -34,7 +34,7 @@ com.gitee.sop sop-bridge-gateway - 3.1.1-SNAPSHOT + 3.1.2-SNAPSHOT diff --git a/sop-test/src/main/resources/img.png b/sop-test/src/main/resources/img.png new file mode 100644 index 00000000..821d3a66 Binary files /dev/null and b/sop-test/src/main/resources/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 5f7c4d1d..a34f26de 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 @@ -239,6 +239,29 @@ public class AllInOneTest extends TestBase { client.execute(requestBuilder); } + /** + * 演示文件上传 + */ + public void testFile3() { + Client client = new Client(url, appId, privateKey); + String root = System.getProperty("user.dir"); + Client.RequestBuilder requestBuilder = new Client.RequestBuilder() + .method("demo.file.upload3") + .version("1.0") + .bizContent(new BizContent().add("remark", "test file upload")) + // 添加文件 + .addFile("image", new File(root + "/src/main/resources/img.png")) + .callback((requestInfo, responseData) -> { + System.out.println(responseData); + JSONObject jsonObject = JSON.parseObject(responseData); + JSONObject data = jsonObject.getJSONObject(requestInfo.getDataNode()); + Assert.assertEquals(data.getString("code"), "10000"); + }) + ; + + client.execute(requestBuilder); + } + /** * 下载文件 */ diff --git a/sop-website/pom.xml b/sop-website/pom.xml index 318cdbd4..f9b64410 100644 --- a/sop-website/pom.xml +++ b/sop-website/pom.xml @@ -35,7 +35,7 @@ com.gitee.sop sop-gateway-common - 3.1.1-SNAPSHOT + 3.1.2-SNAPSHOT