feat(req-2119):修改下载接口

This commit is contained in:
胡朝飞 2024-03-08 16:26:46 +08:00
parent 3c407ebbe2
commit 2e1fcda0b1
2 changed files with 26 additions and 10 deletions

View File

@ -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) {
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();
}
}
}
}
}

View File

@ -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 {
/**