feat(req-2119):修改下载接口
This commit is contained in:
parent
3c407ebbe2
commit
2e1fcda0b1
@ -319,15 +319,31 @@ public class WebFileController {
|
|||||||
ServerFileDownloadDto dto = new ServerFileDownloadDto();
|
ServerFileDownloadDto dto = new ServerFileDownloadDto();
|
||||||
dto.setFileKey(fileUuId);
|
dto.setFileKey(fileUuId);
|
||||||
ServerFileDownloadResponse result = fileService.getObject(dto, FileDownloadTypeEnum.STREAM_DOWNLOAD.getCode());
|
ServerFileDownloadResponse result = fileService.getObject(dto, FileDownloadTypeEnum.STREAM_DOWNLOAD.getCode());
|
||||||
try (OutputStream outputStream = response.getOutputStream(); InputStream inputStream = result.getFileStream()) {
|
|
||||||
// response.setContentType("application/octet-stream");
|
byte[] buff = new byte[1024];
|
||||||
response.setHeader("content-type","application/octet-stream");
|
InputStream is = null;
|
||||||
response.addHeader("Content-Disposition", "attachment;filename=" + result.getFileName() + "." + result.getFileFormat());
|
OutputStream os = null;
|
||||||
// response.setCharacterEncoding("UTF-8");
|
try {
|
||||||
IOUtils.copy(inputStream, outputStream);
|
os = response.getOutputStream();
|
||||||
log.info("文件转换成功");
|
is = result.getFileStream();
|
||||||
} catch (Exception e) {
|
int i = is.read(buff);
|
||||||
e.printStackTrace();
|
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();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -20,7 +20,7 @@ import static org.springframework.http.MediaType.MULTIPART_FORM_DATA_VALUE;
|
|||||||
*/
|
*/
|
||||||
@FeignClient(
|
@FeignClient(
|
||||||
name = "oss",
|
name = "oss",
|
||||||
url = "http://localhost:9123"
|
url = "http://oss:9123"
|
||||||
)
|
)
|
||||||
public interface WebFileServiceApi {
|
public interface WebFileServiceApi {
|
||||||
/**
|
/**
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user