From 2345d1f275354afc430060514f11ecb455e7a15f Mon Sep 17 00:00:00 2001 From: zxh <279049017@qq.com> Date: Mon, 31 Aug 2020 19:38:04 +0800 Subject: [PATCH] 修改 为requestbody --- kidgrow-business/kidgrow-filecenter/kidgrow-filecenter-server/src/main/java/com/kidgrow/filecenter/controller/FileController.java | 23 ++++++++++++++++++++++- 1 files changed, 22 insertions(+), 1 deletions(-) diff --git a/kidgrow-business/kidgrow-filecenter/kidgrow-filecenter-server/src/main/java/com/kidgrow/filecenter/controller/FileController.java b/kidgrow-business/kidgrow-filecenter/kidgrow-filecenter-server/src/main/java/com/kidgrow/filecenter/controller/FileController.java index 9d4a3e2..205ddd3 100644 --- a/kidgrow-business/kidgrow-filecenter/kidgrow-filecenter-server/src/main/java/com/kidgrow/filecenter/controller/FileController.java +++ b/kidgrow-business/kidgrow-filecenter/kidgrow-filecenter-server/src/main/java/com/kidgrow/filecenter/controller/FileController.java @@ -13,6 +13,8 @@ import javax.annotation.Resource; import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; +import java.io.IOException; import java.io.InputStream; import java.util.Map; @@ -89,7 +91,7 @@ * byte[]上传 */ @PostMapping(value="byteUplaod",produces = {MediaType.APPLICATION_JSON_UTF8_VALUE},consumes = MediaType.MULTIPART_FORM_DATA_VALUE) - public FileInfo byteUplaod(@RequestParam("fileName") String fileName,@RequestParam("byte[]") byte[] bytes){ + public FileInfo byteUplaod(@RequestBody String fileName,@RequestBody byte[] bytes){ if(bytes.length == 0){ return null; } @@ -99,6 +101,25 @@ InputStream inputStream = new ByteArrayInputStream(bytes); return fileService.byteUplaod(fileName,inputStream,bytes.length); } + /** + * byte[]上传 + */ + @PostMapping(value="byteUplaodTest",produces = {MediaType.APPLICATION_JSON_UTF8_VALUE},consumes = MediaType.MULTIPART_FORM_DATA_VALUE) + public FileInfo byteUplaodTest(@RequestParam("fileName") String fileName,@RequestPart("file") MultipartFile file)throws IOException { + InputStream inputStream = file.getInputStream(); + ByteArrayOutputStream bytestream = new ByteArrayOutputStream(); + byte[] buffer=new byte[1024]; + int ch; + /** + * + * */ + while ((ch = inputStream.read(buffer)) != -1) { + bytestream.write(buffer,0,ch); + } + byte[] data = bytestream.toByteArray(); + InputStream inputStream1 = new ByteArrayInputStream(data); + return fileService.byteUplaod(fileName,inputStream,data.length); + } /** * 文件删除 -- Gitblit v1.8.0