Click here to Skip to main content
15,899,026 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
im a student at the Durban University of technology currently doing my 3rd year and we are given a project where by we approach organisations and develop applications for those organisations,and im developing a web application for a Drama department at a local university and im not clear on how to do a database that will store pictures and videos ,if anyone knows how to go about doing it please help :)
Posted

Unless your images and videos absolutely have to be stored in the database, I would recommend storing them on the file system and use the database to store references to the file system location.

For example; a table with columns for video name,rating and location on the file system (or file share) should do. Additional related tables can then be used for things like "tags" or associations between videos so that meaningful searches can be conducted. I think it makes sense to extract information such as format, duration, encoding etc, from the video and store this in the video table as well so that searches can be run on these properties without having to actually look at the video file.
 
Share this answer
 
There are a lot of things to consider here.

  • Actual Database Server, is it SQL Server, Oracle etc.
  • Are you planning on storing the file IN the database, or storing the location and leaving the file on the filesystem somewhere?
  • If you are storing the files IN the database, how large is your database allowed to be, how large of files can your database hold, etc.


I have seen proof that certain databases are faster at retrieving files than the filesystem. Additionally you don't have to worry about accidental removal of a file or corruption of a file on the filesystem if you store it in the database. Finally an additional benefit to storing the files in the database is, you don't have to worry about filesystem permissions.

Storage limitations of the database is the greatest drawback of storing the images IN the database.

Here is an article from Oracle on doing this.


Assuming you want to stuff files into a database fits your needs, you can use a connected dataset, a O/R mapper (like nhibernate) or you can do it simply with parameterized SQL.
C#
//get the connection string from the app.config or web.config
var css = ConfigurationManager.ConnectionStrings["DSN"];
//get the content of the file
byte[] fileData = System.IO.File.ReadAllBytes("filename.flv");
//get the factory
var factory = DbProviderFactories.GetFactory(css.ProviderName);
using (var conn = factory.CreateConnection())
{
    var csb = factory.CreateConnectionStringBuilder() ?? new DbConnectionStringBuilder(true);
    //validate and properly encode the connection string
    csb.ConnectionString = css.ConnectionString;
    conn.ConnectionString = csb.ConnectionString;
    //open the connection
    conn.Open();
    using (var cmd = conn.CreateCommand())
    {
        //add the parameter for the ID
        var parameter = factory.CreateParameter();
        parameter.DbType = DbType.Binary;
        parameter.ParameterName = "id";
        parameter.Value = Guid.NewGuid().ToByteArray();
        cmd.Parameters.Add(parameter);

        //add a new parameter for the NAME
        parameter = factory.CreateParameter();
        parameter.DbType = DbType.String;
        parameter.ParameterName = "name";
        parameter.Value = "filename"; //the name of the file
        cmd.Parameters.Add(parameter);

        //add a new parameter for the data
        parameter = factory.CreateParameter();
        parameter.DbType = DbType.String;
        parameter.ParameterName = "name";
        parameter.Value = fileData; //the bytes we read in earlier
        cmd.Parameters.Add(parameter);

        cmd.CommandText = @"insert into `Test`.`imagetable`
                          (`ID`, `Name`, `data`) values
                          (?id, ?name ,?data)";
    }
}



The SQL in this example is hardcoded to use MySQL (but its ONLY the SQL that forces it to be mySQL). You can see how to make this more database independent in some of my articles.

Don't hard code your DataProviders

Using Information from the .NET DataProvider
 
Share this answer
 
v3

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900