feat(req-2119):远程下载接口---逻辑修改
This commit is contained in:
parent
603cf218c8
commit
4c064e8102
@ -312,38 +312,27 @@ public class WebFileController {
|
||||
}
|
||||
}
|
||||
|
||||
@SneakyThrows
|
||||
/**
|
||||
* 远程下载接口
|
||||
*
|
||||
* @param fileUuId 文件uuid
|
||||
* @param response HttpServletResponse
|
||||
*/
|
||||
@GetMapping("/v1/obs/downloadFileFromObs")
|
||||
@CrossOrigin
|
||||
public void downloadFileFromObs(@RequestParam("fileUuid") String fileUuId, HttpServletResponse response) {
|
||||
ServerFileDownloadDto dto = new ServerFileDownloadDto();
|
||||
dto.setFileKey(fileUuId);
|
||||
ServerFileDownloadResponse result = fileService.getObject(dto, FileDownloadTypeEnum.STREAM_DOWNLOAD.getCode());
|
||||
|
||||
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();
|
||||
}
|
||||
}
|
||||
try (OutputStream outputStream = response.getOutputStream(); InputStream inputStream = result.getFileStream()) {
|
||||
response.setHeader("content-type","application/octet-stream");
|
||||
response.setContentType("application/octet-stream");
|
||||
response.setCharacterEncoding("UTF-8");
|
||||
response.addHeader("Content-Disposition", "attachment;filename=" + result.getFileName() + "." + result.getFileFormat());
|
||||
IOUtils.copy(inputStream, outputStream);
|
||||
log.info("response设置文件流成功");
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user