获取文件流优化调整

This commit is contained in:
tianliyong 2022-12-20 14:28:44 +08:00
parent dca534c3cb
commit 76ad1d78f1
3 changed files with 7 additions and 3 deletions

View File

@ -112,14 +112,16 @@ public class WebFileController {
@SneakyThrows
@GetMapping("/v1/file/download")
@CrossOrigin
@PreBuildContext
//@PreBuildContext
public void download(@Valid ServerFileDownloadDto dto, HttpServletResponse response) {
ServerFileDownloadResponse result = fileService.download(dto);
InputStream inputStream = null;
OutputStream outputStream = response.getOutputStream();
try {
inputStream = result.getFileStream();
response.setContentType("application/x-download");
//response.setContentType("application/x-download");
response.setContentType("image/jpg");
response.setCharacterEncoding("UTF-8");
response.addHeader("Content-Disposition", "attachment;filename=" + result.getFileName() + "." + result.getFileFormat());
IOUtils.copy(inputStream, outputStream);
} catch (Exception e) {

View File

@ -43,6 +43,8 @@ public enum CodeEnum implements EnumBase<Integer> {
MISSING_REQUEST_PARAM(110, "missing request param"),
FILE_NAME_TOO_LONG(111, "file name too long max 128"),
FILE_NOT_FOUND(112, "file not found"),
;
private final Integer code;

View File

@ -151,7 +151,7 @@ public class FileServiceImpl implements FileService {
File file = fileDao.getByFileUuid(fileKey);
if (Utility.objIsNull(file)) {
log.warn("file download is null, fileKey = {}", fileKey);
return null;
BizException.error(Utility.objIsNotNull(file), CodeEnum.FILE_NOT_FOUND);
}
String tgtFileKey = Utility
.generateFileKey(file.getDirectory(), file.getFileUuid(), file.getFileFormat());