From 2e1fcda0b105422d37555b6975978871140bc872 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=83=A1=E6=9C=9D=E9=A3=9E?= Date: Fri, 8 Mar 2024 16:26:46 +0800 Subject: [PATCH] =?UTF-8?q?feat(req-2119):=E4=BF=AE=E6=94=B9=E4=B8=8B?= =?UTF-8?q?=E8=BD=BD=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../client/controller/WebFileController.java | 34 ++++++++++++++----- .../axzo/oss/http/api/WebFileServiceApi.java | 2 +- 2 files changed, 26 insertions(+), 10 deletions(-) diff --git a/oss-client/src/main/java/cn/axzo/oss/client/controller/WebFileController.java b/oss-client/src/main/java/cn/axzo/oss/client/controller/WebFileController.java index ed30958..37bb953 100644 --- a/oss-client/src/main/java/cn/axzo/oss/client/controller/WebFileController.java +++ b/oss-client/src/main/java/cn/axzo/oss/client/controller/WebFileController.java @@ -319,15 +319,31 @@ public class WebFileController { ServerFileDownloadDto dto = new ServerFileDownloadDto(); dto.setFileKey(fileUuId); ServerFileDownloadResponse result = fileService.getObject(dto, FileDownloadTypeEnum.STREAM_DOWNLOAD.getCode()); - try (OutputStream outputStream = response.getOutputStream(); InputStream inputStream = result.getFileStream()) { - // response.setContentType("application/octet-stream"); - response.setHeader("content-type","application/octet-stream"); - response.addHeader("Content-Disposition", "attachment;filename=" + result.getFileName() + "." + result.getFileFormat()); - // response.setCharacterEncoding("UTF-8"); - IOUtils.copy(inputStream, outputStream); - log.info("文件转换成功"); - } catch (Exception e) { - e.printStackTrace(); + + byte[] buff = new byte[1024]; + InputStream is = null; + OutputStream os = null; + try { + os = response.getOutputStream(); + is = result.getFileStream(); + int i = is.read(buff); + while (i != -1) { + os.write(buff, 0, buff.length); + os.flush(); + i = is.read(buff); + } + log.info("oss下载完成"); + } catch (IOException e2){ + e2.printStackTrace(); + } finally { + if (is != null) { + try { + is.close(); + //os.close(); + } catch (IOException e) { + e.printStackTrace(); + } + } } } } diff --git a/oss-http-api/src/main/java/cn/axzo/oss/http/api/WebFileServiceApi.java b/oss-http-api/src/main/java/cn/axzo/oss/http/api/WebFileServiceApi.java index e746464..8af040a 100644 --- a/oss-http-api/src/main/java/cn/axzo/oss/http/api/WebFileServiceApi.java +++ b/oss-http-api/src/main/java/cn/axzo/oss/http/api/WebFileServiceApi.java @@ -20,7 +20,7 @@ import static org.springframework.http.MediaType.MULTIPART_FORM_DATA_VALUE; */ @FeignClient( name = "oss", - url = "http://localhost:9123" + url = "http://oss:9123" ) public interface WebFileServiceApi { /**