在标头中添加http字节范围

问题描述

我的网站上存在视频向后和向前搜索的问题(仅在Chrome浏览器中)。

我想出了HTTP标头的问题。

我当前的返回视频的控制器方法


@RequestMapping(value = "/cuser/videofetch/{enrollid}")
    public void openVideoFile(@PathVariable("enrollid") int accountId,HttpServletResponse response,HttpServletRequest httpServletRequest) {
        try {
            String videoFilePath = xmlKycService.getEnrollmentVideoPathBy(accountId);
            LOGGER.info("enroll id:"+accountId+"VideoFilePath: "+videoFilePath);
            if (videoFilePath == null || videoFilePath.isEmpty()) {
                response.setContentType("text/html");
                response.getoutputStream().write("<br><br><h3>File Not Found / Not Uploaded</h3>".getBytes());
                response.flushBuffer();
                return;
            }
            if (videoFilePath.contains("Uploads")) {
                String profile = System.getProperty("spring.profiles.active");
                if(profile!=null && profile.equalsIgnoreCase("prod_dr")){
                    videoFilePath = videoFilePath.replace("192.168.10.21","192.168.50.24");
                }
                
            } else {
                videoFilePath = FolderUtil.getFullPath(videoFilePath);
            }

            File file = new File(videoFilePath);
            String contentType = null;
            contentType = Files.probeContentType(file.toPath());
            LOGGER.debug("contentType:" + contentType);
            response.setContentType(contentType);
            response.addheader("Content-disposition","attachment;filename=" + accountId + ".mp4");
            InputStream in = new FileInputStream(videoFilePath);
            OutputStream out = response.getoutputStream();
            if (videoFilePath.contains("Uploads")) {
                out.write(AESEncryption.getFile(videoFilePath));
            } else {
                out.write(
                        AESEncryption.decryptFile(AESEncryption.getStaticKey(),AESEncryption.getFile(videoFilePath)));
            }

        } catch (Exception e) {
            LOGGER.error("",e);
        }

    }

由于某些浏览器不支持字节范围请求,因此该如何添加

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)