前台视频使用blob加密src路径
下面我们将video标签中的src使用blob进行加密,下面我们来看一个已加密视频的src的图片
加密截图
jsp页面JQ前台加密处理代码:
var video = document.getElementById("myVideo");
window.URL = window.URL || window.webkitURL;
var xhr = new XMLHttpRequest();
xhr.open("POST", "${ctx}/VideoParticulars/getUserVideo.do?file=" + url,
true);
xhr.responseType = "blob";
xhr.onload = function() {
if (this.status == 200) {
var blob = this.response;
video.onload = function(e) {
window.URL.revokeObjectURL(video.src);
};
video.src = window.URL.createObjectURL(blob);
}
;
};
xhr.send();
视频格式名称:
后台像返回视频格式就可以了
Java控制器代码
@SuppressWarnings("unused")
@RequestMapping("/getUserVideo")
private void getUserPicture(HttpServletRequest request,
HttpServletResponse response) throws ServletException, IOException {
String strFileName = request.getParameter("file");
// 构建上传目录的路径
String uploadPath = "G:\\JAVA\\livePlug-in\\MasterPeiYou\\WebRoot\\WEB-INF\\jsp\\CourseVideo";
if (Tools.isNotNull(strFileName)) {
File file = new File(uploadPath + File.separator + strFileName);
if (file.exists() && file.isFile()) {
FileInputStream in = new FileInputStream(file);
ServletOutputStream out = response.getOutputStream();
byte[] buf = new byte[1024];
int count = 0;
while (-1 != (count = in.read(buf, 0, buf.length))) {
out.write(buf, 0, count);
}
response.setContentType("video/mp4"); // 设置返回的文件类型
out.flush();
out.close();
in.close();
}
}
}
这样就完成了