@Async
public CompletableFuture<ResponseEntity<ByteArrayResource>> handleFileDownload(Integer id) throws UnsupportedEncodingException {
Optional<AppVersion> fileEntityOptional = service.getFile(id);
if (!fileEntityOptional.isPresent()) {
return CompletableFuture.completedFuture(ResponseEntity.status(HttpStatus.NOT_FOUND).body(null));
}
AppVersion fileEntity = fileEntityOptional.get();
ByteArrayResource resource = new ByteArrayResource(fileEntity.getAppFile());
String downloadFilename = fileEntity.getName() + UploadCheckUtils.YES_APK_SUPPORT;
String encodedFilename = URLEncoder.encode(downloadFilename, "UTF-8").replaceAll("\\+", "%20");
ResponseEntity<ByteArrayResource> response = ResponseEntity.ok()
.header(HttpHeaders.CONTENT_DISPOSITION, "attachment; filename=\"" + encodedFilename + "\"")
.header(HttpHeaders.CONTENT_TYPE, "application/vnd.android.package-archive")
.contentLength(fileEntity.getAppFile().length)
.body(resource);
return CompletableFuture.completedFuture(response);
}
数据库longblob类型文件流下载
最新推荐文章于 2026-06-18 21:05:44 发布
296

被折叠的 条评论
为什么被折叠?



