나는 데이터베이스에 비디오를 저장하고 데이터베이스에서 다운로드하기 위해 그리드에 표시하려는 시나리오가 있습니다. fileupload 컨트롤로 비디오를 업로드하고 C# 및 asp.net에서 가장 좋은 방법은 SQL Server2008 데이터베이스 여야합니다. 그것은 당신을 도울 것입니다C#을 사용하여 비디오를 데이터베이스에 저장하는 방법?
답변
는 아래의 링크를 참조하십시오. 이것 좀 봐.
http://forums.asp.net/t/1104451.aspx/1?How+to+retrieve+video+file+from+sql+server+database http://www.saurabhdeveloper.com/techtips_details.php?tipsid=15 http://forums.asp.net/p/1533758/3719583.aspx http://forums.asp.net/t/1045855.aspx/2/10 http://forums.asp.net/t/1511588.aspx/1 http://www.dotnetspider.com/forum/274821-Play-video-file-asp-net-page.aspxhttp://blogs.ugidotnet.org/kfra/archive/2006/10/04/50003.aspx http://www.dotnetspider.com/resources/16239-code-for-video-upload.aspx
http://www.c-sharpcorner.com/Forums/Thread/88899/ http://www.asp.net/webmatrix/tutorials/10-working-with-video
,691,363 (210)http://www.c-sharpcorner.com/Forums/Thread/88899/
byte[] buffer;
//this is the array of bytes which will hold the data (file)
SqlConnection connection;
protected void ButtonUpload_Click(object sender, EventArgs e)
{
//check the file
if (FileUpload1.HasFile && FileUpload1.PostedFile != null
&& FileUpload1.PostedFile.FileName != "")
{
HttpPostedFile file = FileUpload1.PostedFile;
//retrieve the HttpPostedFile object
buffer = new byte[file.ContentLength];
int bytesReaded = file.InputStream.Read(buffer, 0,
FileUpload1.PostedFile.ContentLength);
if (bytesReaded > 0)
{
try
{
string connectionString =
ConfigurationManager.ConnectionStrings[
"uploadConnectionString"].ConnectionString;
connection = new SqlConnection(connectionString);
SqlCommand cmd = new SqlCommand
("INSERT INTO Videos (Video, Video_Name, Video_Size)" +
" VALUES (@video, @videoName, @videoSize)", connection);
cmd.Parameters.Add("@video",
SqlDbType.VarBinary, buffer.Length).Value = buffer;
cmd.Parameters.Add("@videoName",
SqlDbType.NVarChar).Value = FileUpload1.FileName;
cmd.Parameters.Add("@videoSize",
SqlDbType.BigInt).Value = file.ContentLength;
using (connection)
{
connection.Open();
int i = cmd.ExecuteNonQuery();
Label1.Text = "uploaded, " + i.ToString() + " rows affected";
}
}
catch (Exception ex)
{
Label1.Text = ex.Message.ToString();
}
}
}
else
{
Label1.Text = "Choose a valid video file";
}
}
이 링크에서 유용한 데이터를 추출해 주시겠습니까? 그것은 아주 압도적입니다! – rhughes
@rhughes는 내 대답을 참조하십시오. –
당신이 말을이 코드를 시도 SQL Server 2008의 수 "있어야"하지만해야합니까?
그렇지 않은 경우 SQL Server 2012는 SQL Server에 큰 파일을 저장하도록 설계된 File Tables을 제공합니다. 실제로 파일 시스템에 데이터를 저장하지만 실제 파일을 관리하기 위해 코드를 작성할 필요는 없습니다.
는 SQL Server 2008을 할 필요가없는 경우
은 다음과 같은 옵션이하십시오 VARBINARY (MAX) 열 유형을 사용하여1) FileStream를 -이 방법 성능 문제가있을 수 있습니다. 나는 개인적으로 이런 식으로 비디오를 저장하지 않을 것이다.
2) 파일을 파일 시스템 (디스크)에 넣고 파일 경로/파일 이름 만 DB에 저장하십시오. 그런 다음 파일 시스템에서 CRUD 작업을 관리하는 코드를 작성합니다.
데이터베이스에 비디오를 저장하지 마십시오. 테이블에 이름 만 저장하고 폴더에 비디오를 업로드하십시오. 이것은 내가 가장 좋은 방법이라고 생각합니다. – Shashank