瀏覽代碼

fix: 修复上传MP4文件之后通过下载连接下载MP4文件源文件能通过windows自带播放器播放下载下来的播放不了

puhui999 1 年之前
父節點
當前提交
a5ad8bb708

+ 2 - 3
yudao-module-infra/src/main/java/cn/iocoder/yudao/module/infra/framework/file/core/utils/FileTypeUtils.java

@@ -3,7 +3,6 @@ package cn.iocoder.yudao.module.infra.framework.file.core.utils;
 import cn.hutool.core.io.IoUtil;
 import cn.hutool.core.util.StrUtil;
 import cn.iocoder.yudao.framework.common.util.http.HttpUtils;
-import com.alibaba.ttl.TransmittableThreadLocal;
 import jakarta.servlet.http.HttpServletResponse;
 import lombok.SneakyThrows;
 import lombok.extern.slf4j.Slf4j;
@@ -86,8 +85,8 @@ public class FileTypeUtils {
         response.setContentType(contentType);
         // 针对 video 的特殊处理,解决视频地址在移动端播放的兼容性问题
         if (StrUtil.containsIgnoreCase(contentType, "video")) {
-            response.setHeader("Content-Length", String.valueOf(content.length - 1));
-            response.setHeader("Content-Range", String.valueOf(content.length - 1));
+            response.setHeader("Content-Length", String.valueOf(content.length));
+            response.setHeader("Content-Range", "bytes 0-" + (content.length - 1) + "/" + content.length);
             response.setHeader("Accept-Ranges", "bytes");
         }
         // 输出附件