I'm using node and express. I want to control the access to the video files in a way that they will reside on the public folder (so they can be served to the client) but also not be directly accessible by non-authorized users through a url on the browser.
I want to serve the videos to the client using the usual html5 video tag:
<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>
Is this possible? How can it be implemented? Thanks
----------------------- Solved this way: ---------------------
Solved it using middleware. Is was much simpler than I though it would be.
I placed the files on the videos folder residing on the public folder of my app. Though I added this line to my application.js file:
app.get('/videos/*', authenticationFunction(), function(req, res, next) {
next();
});
The authenticationFunction checks if the user is allowed or not to access any file on the videos folder.
The authenticationFunction looks like this:
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'));
}
}
}
Finally on the app configuration on the app.use function I added an "unauthorized video access" error handling part.
Thanks anyway
Declare it as a static assets folder:
app.use(express.static(__dirname + 'videos/'));
Example:
videos/
├── vid1
│
├── vid2
│
└── vid3
public/
├── css/
│ ├── ...
│ └── ...
├── js/
│ ├── ...
│ └── ...
└── img/
├── ...
└── ....