From afb0fa2343163188cdfc99a9ac90cbabce63ca82 Mon Sep 17 00:00:00 2001 From: zxh <279049017@qq.com> Date: Tue, 01 Sep 2020 14:28:01 +0800 Subject: [PATCH] 修改上传byte数组接口 --- kidgrow-business/kidgrow-filecenter/kidgrow-filecenter-server/src/main/java/com/kidgrow/filecenter/controller/FileController.java | 42 ++++++++++++++++++++++++++++++++++++++++-- 1 files changed, 40 insertions(+), 2 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 4341125..b70149c 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 @@ -12,6 +12,10 @@ import org.springframework.web.multipart.MultipartFile; import javax.annotation.Resource; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; +import java.io.IOException; +import java.io.InputStream; import java.util.Map; /** @@ -68,8 +72,9 @@ * base64上传图片 */ @PostMapping(value="baseUplaod",produces = {MediaType.APPLICATION_JSON_UTF8_VALUE},consumes = MediaType.MULTIPART_FORM_DATA_VALUE) - public FileInfo baseUplaod(@RequestParam("file") String file,@RequestParam("imgType") String imgType){ - return fileService.baseUplaod(file,imgType); + public FileInfo baseUplaod(@RequestParam("file") String file,@RequestParam("imgType") String imgType, + @RequestParam("hospitalId") String hospitalId,@RequestParam("departmentId") String departmentId){ + return fileService.baseUplaod(file,imgType,hospitalId,departmentId); } /** * base64图片下载 @@ -82,6 +87,39 @@ } return fileService.baseDownLoad(map); } + /** + * byte[]上传 + */ + @PostMapping(value="byteUplaod") + public FileInfo byteUplaod(@RequestParam("fileName") String fileName,@RequestBody byte[] bytes){ + if(bytes.length == 0){ + return null; + } + if (com.kidgrow.common.utils.StringUtils.isBlank(fileName)) { + return null; + } + 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