how to read and write MP3 to database

若如初见. 提交于 2019-12-19 04:56:21

问题


how to read MP3 from Sql database. in sql i have stored the file as binary format. now i want to retrive the Mp3 file stored in the sql and show in my aspx page. how????

pls help...


回答1:


In its simplest form this is how you would get the raw bytes, can't really show any more without knowing what you want it for...

private byte[] GetMp3Bytes(string connString)
{
   SqlConnection conn = null;
   SqlCommand cmd = null;
   SqlDataReader reader = null;

   using (conn = new SqlConnection(connString))
   {
      conn.Open();

      using (cmd = new SqlCommand("SELECT TOP 1 Mp3_File FROM MP3_Table", conn))
      using (reader = cmd.ExecuteReader())
      {
          reader.Read();
          return reader["Mp3_File"] as byte[];
      }
   }
}



回答2:


You'd probably want to use a Generic ASHX Handler that retrieves the binary data and streams it to the response stream with the correct content-type header ("audio/mpeg").

If you look at the article Displaying Images in ASP.NET Using HttpHandlers then you should see the basic principle. You just need to change the content-type output.



来源:https://stackoverflow.com/questions/3458201/how-to-read-and-write-mp3-to-database

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!