Hi,
I need advice for project in which i stored video from admin and retrive(show) on user side.
So, what is best way to for this also with performance wice.
note: i am using dot net ,c#
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Afzaal Ahmad ZeeshanPosted Jul 2, 2016, 5:56 PM
First thing that I want to say here is that you should never save a media file in the database, for many reasons! For example,
- Database space is really expensive as compared to the file system.
- Database space should be (and could be used efficiently!) if you use it to work with text-data. BLOB data can be confusing.
- Database requires a database engine such as SQL Server running all the time. That is why, it would always be consuming extra resources on your server, memory and CPU, plus the video file would require to be active in the query too.
Given these reasons, my recommendation is to not save the media file in the database at all. What I do is that I just save the names of the files in the database and then I load the content from the file system, this way I save a lot of stuff from being confusing. Such as:- If you store the video in the database, you also have to store the MIME-type, content length, content (as byte array) in the database.
- To read the file, you need the rest of the data too!
- To render the file, you end up again converting the record to a file (using those data).
These create a overhead process which can be simply removed as,Of course this will be much simpler using the native HTML controls such as, video element.
Other methods would be much more complex. This method is simpler because it doesn't require much more complex typing, and if you are very suspicious about the users who consume the service, my recommendation is to authorize every request to the controller. You can do the following to your controller, (assuming you are using ASP.NET),
Why is this better?
Because your users are no longer relying on the SQL Server to be responding with the buffers of media, instead your clients are directly connected with the static file on the server and they are using that file directly in their browsers. This enhances speed.