-1
我正在使用節點和快車。我想控制對視頻文件的訪問,以便它們駐留在公共文件夾中(這樣它們可以被提供給客戶端),但也不能由非授權用戶通過瀏覽器上的URL直接訪問。node.js和express。無法直接訪問mp4&ogg文件的html5視頻
我想用通常的HTML5視頻標籤,以服務客戶端視頻:
<video width="320" height="240" controls>
<source src="mp4 video file" type="video/mp4">
<source src="ogg video file" type="video/ogg">
Your browser does not support the video tag.
</video>
這可能嗎?它如何實施? 謝謝
-----------------------解決方法如下:---------------- -----
使用中間件解決了它。雖然它會比我簡單得多。
我將文件放在駐留在我的應用程序公用文件夾中的視頻文件夾中。雖然我加入這行到我的application.js文件:
app.get('/videos/*', authenticationFunction(), function(req, res, next) {
next();
});
如果用戶允許的authenticationFunction檢查或不訪問的視頻文件夾中的任何文件。
的authenticationFunction看起來是這樣的:
var authenticationFunction = function(){
return function(req, res, next) {
if(the user is authorized to access the files){
return next();
} else{
return next(new Error('unauthorized video access'));
}
}
}
最後上的app.use功能的應用程序的配置我增加了一個「未經授權的視頻訪問」錯誤處理部分。
由於無論如何