| | |
| | | import com.kidgrow.common.model.ResultBody; |
| | | import com.kidgrow.filecenter.model.FileInfo; |
| | | import com.kidgrow.filecenter.service.IFileService; |
| | | import org.apache.commons.collections4.MapUtils; |
| | | import org.apache.commons.lang3.StringUtils; |
| | | import org.springframework.http.MediaType; |
| | | import org.springframework.web.bind.annotation.*; |
| | | 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; |
| | | |
| | | /** |
| | |
| | | return fileService.uploadForThumbnails(file,imgType); |
| | | } |
| | | /** |
| | | * 文件上传 根据fileType选择上传方式 hospitalId departmentId |
| | | * @param file |
| | | * @return |
| | | */ |
| | | @PostMapping(value="/feignUploadHosIdAndDepId",produces = {MediaType.APPLICATION_JSON_UTF8_VALUE},consumes = MediaType.MULTIPART_FORM_DATA_VALUE) |
| | | public FileInfo feignUploadHosIdAndDepId(@RequestPart("file") MultipartFile file,@RequestParam("imgType") String imgType,@RequestParam("hospitalId") String hospitalId,@RequestParam("departmentId") String departmentId) throws Exception { |
| | | return fileService.feignUploadHosIdAndDepId(file,imgType,hospitalId,departmentId); |
| | | } |
| | | /** |
| | | * 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图片下载 |
| | | */ |
| | | @PostMapping(value="baseDownLoad",produces = {MediaType.APPLICATION_JSON_UTF8_VALUE},consumes = MediaType.MULTIPART_FORM_DATA_VALUE) |
| | | public ResultBody baseDownLoad(@RequestBody Map<String,Object> map){ |
| | | @PostMapping(value="baseDownLoad") |
| | | public ResultBody baseDownLoad(@RequestBody Map<String,Object> map) throws Exception{ |
| | | String url = MapUtils.getString(map, "url"); |
| | | if (StringUtils.isBlank(url)) { |
| | | return ResultBody.failed("请输入地址"); |
| | | } |
| | | return fileService.baseDownLoad(map); |
| | | } |
| | | /** |
| | | * byte[]上传 |
| | | */ |
| | | @PostMapping(value="byteUplaod") |
| | | public FileInfo byteUplaod(@RequestParam("fileName") String fileName,@RequestBody byte[] bytes) throws IOException{ |
| | | 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); |
| | | } |
| | | |
| | | /** |
| | | * 文件删除 |