From 7bc99849f435610d14ca95fc3b4af670cefc3846 Mon Sep 17 00:00:00 2001 From: Wzp-2008 Date: Mon, 21 Apr 2025 00:31:34 +0800 Subject: [PATCH] fix: fix part download cannot end successful bug --- .../cn/wzpmc/filemanager/service/FileService.java | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/main/java/cn/wzpmc/filemanager/service/FileService.java b/src/main/java/cn/wzpmc/filemanager/service/FileService.java index 330e012..c1d76b9 100644 --- a/src/main/java/cn/wzpmc/filemanager/service/FileService.java +++ b/src/main/java/cn/wzpmc/filemanager/service/FileService.java @@ -309,7 +309,7 @@ public class FileService { } long size = fileVo.getSize(); long min = 0; - long max = size; + long max = size - 1; if (!range.equals("null")) { String[] unitRanges = range.split("="); String[] minMax = unitRanges[1].split("-"); @@ -321,21 +321,22 @@ public class FileService { } response.setStatus(206); response.addHeader("Content-Range", "bytes " + min + "-" + max + "/" + size); + response.addHeader("Accept-Ranges", "bytes"); } else { response.setStatus(200); } - // log.info("-------Prepare-Response-{}-{}-------", min, max); + log.debug("-------Prepare-Response-{}-{}-{}-------", min, max, id); String hash = fileVo.getHash(); String fullName = fileVo.getName(); String ext = fileVo.getExt(); if (ext != null) { fullName += '.' + ext; } - response.addHeader("Content-Length", String.valueOf(max - min)); + response.addHeader("Content-Length", String.valueOf(max - min + 1)); ContentDisposition disposition = ContentDisposition.attachment().filename(fullName, StandardCharsets.UTF_8).build(); response.addHeader("Content-Disposition", disposition.toString()); File file = new File(properties.getSavePath(), hash); - // log.info("-------Copy-{}-{}-------", min, max); + log.debug("-------Copy-{}-{}-{}-------", min, max, id); try (ServletOutputStream outputStream = response.getOutputStream()) { InputStream stream = null; try { @@ -360,7 +361,7 @@ public class FileService { response.reset(); } } - // log.info("-------flush-{}-{}-------", min, max); + log.debug("-------flush-{}-{}-{}-------", min, max, id); } public Result getFileLink(long id, String address, HttpServletRequest request) {