我有場景,我想存儲視頻到數據庫和網格顯示從數據庫下載,我會上傳視頻通過fileupload控制,它應該是sql server2008數據庫,這是最好的方式在C#和asp.net?如何使用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.aspx http://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
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提供File Tables,專門用於在SQL Server中存儲大型文件。它實際上將數據存儲在文件系統中,但是不需要編寫任何代碼來管理實際文件。
如果確實需要的SQL Server 2008,那麼你有以下幾種選擇:
1)FileStream用VARBINARY(MAX)列類型 - 可以有這種方法的性能問題。我個人不會以這種方式存儲視頻。
2)將文件放在文件系統上(磁盤上),只將文件路徑/文件名存儲在數據庫中。然後編寫代碼來管理文件系統上的CRUD操作。
- 1. 將視頻保存到核心數據
- 2. 如何將視頻文件保存在數據庫中?
- 3. 將.mp4保存到Windows Phone視頻庫
- 4. 使用C++保存到數據庫
- 5. 將分割視頻保存到數據庫並檢索它們
- 6. 將視頻上傳/保存到數據庫或文件系統
- 7. 將視頻流保存到數據庫的表中
- 8. 使用C#中的fileuploadControl將數據保存到數據庫#
- 9. 如何使用python將數據從hadoop保存到數據庫
- 10. 如何使用SqlCommand將數據保存到sql數據庫
- 11. 如何將數據從DataGridView保存到數據庫中? c#winforms
- 12. 如何將Handsontable保存到數據庫
- 13. 如何將視頻標籤存儲到數據庫(MySQL)?
- 14. 將視頻保存到NSUserDefault
- 15. 使用Swift將視頻文件保存到照片庫
- 16. 使用AVfoundation框架將視頻保存到iPhone庫
- 17. 使用Android FileProvider將照片和視頻保存到圖庫
- 18. 如何將視頻從文檔目錄保存到圖庫?
- 19. c#AForge.NET - 如何將視頻從相機保存到文件中
- 20. 保存視頻到iPad視頻應用
- 21. 如何使用SQLite和PHP將圖像保存到數據庫?
- 22. 如何使用Hibernate將枚舉值保存到數據庫?
- 23. 我如何使用AJAX將DropDown保存到數據庫中
- 24. 如何使用@ Html.DisplayFor將日期保存到數據庫中
- 25. 如何使用ASP.NET Core將圖像保存到數據庫?
- 26. 如何使用Jedis庫將此數據保存到Redis中?
- 27. 如何使用UWP將圖像保存到azure mysql數據庫
- 28. 如何在android中使用volley庫將數據保存到mysql?
- 29. 如何使用EntityFramework將對象更新保存到數據庫?
- 30. 如何將datagridview保存到數據庫使用linq
不要將視頻存儲在數據庫中。將名稱存儲在表格中並上傳視頻文件夾。我覺得這是最好的方法。 – Shashank