我该如何做将代码存储在SQL数据库上的代码 [英] how do i go about doing the code for storing videos on the SQL database

查看:101
本文介绍了我该如何做将代码存储在SQL数据库上的代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

目前,我是德班理工大学的一名学生,这是我三年级的学习.我们得到了一个项目,通过该项目,我们与组织接触并为这些组织开发应用程序,并为当地大学的戏剧系开发Web应用程序.即时消息尚不清楚如何存储图片和视频的数据库,如果有人知道该怎么做,请帮助:)

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 :)

推荐答案

除非您的图片和视频绝对必须存储在数据库中,我建议将它们存储在文件系统中,并使用数据库存储对文件系统位置的引用.

例如;一个带有视频名称,等级和在文件系统(或文件共享)上的位置的列的表应该起作用.然后,其他相关表可用于诸如标签"或视频之间的关联之类的事情,从而可以进行有意义的搜索.我认为从视频中提取诸如格式,时长,编码等信息,并将其存储在视频表中也很有意义,这样就可以在这些属性上运行搜索,而不必实际查看视频文件.
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.


这里有很多事情要考虑.

  • 实际的数据库服务器,是SQL Server,Oracle等.
  • 您是否打算将文件存储在数据库中,或者存储位置并将文件保留在文件系统中的某个位置?
  • 如果要将文件存储在数据库中,则允许数据库的大小,数据库可以容纳的文件大小,等等.
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.
//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)";
    }
}




在此示例中,SQL进行了硬编码以使用MySQL(但只有将其强制为mySQL的SQL).您可以在我的一些文章中了解如何使此数据库更独立.

不要对您的数据提供者进行硬编码

使用来自.NET数据提供程序的信息




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


这篇关于我该如何做将代码存储在SQL数据库上的代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆