如何解决在标头中添加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 举报,一经查实,本站将立刻删除。