在标头中添加http字节范围

时间:2020-08-26 21:08:19

标签: http http-range

我的网站上存在视频向后和向前搜索的问题(仅在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);
        }

    }

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

0 个答案:

没有答案
相关问题