开发者

Retrieve mp3 file from database

开发者 https://www.devze.com 2023-01-12 11:26 出处:网络
I have a question 开发者_如何学Pythonregarding how to retrieve an mp3 file stored as a byte[] array from the database and display it in a form and let the user to download/play it?Hmm. This sure can b

I have a question 开发者_如何学Pythonregarding how to retrieve an mp3 file stored as a byte[] array from the database and display it in a form and let the user to download/play it?


Hmm. This sure can be done but if it is a RDBMS you realy should reconsider the solution. Usualy the database is not designed or optimized for using large binary objects and reading and writing the data is far from beeing optimal.

Why not storing the file in a folder and save the file- and folder-name to the database?


To save the array of bytes as a file that can be downloaded, you can use a FileStream.

byte[] array; //Loaded array of bytes.
using (FileStream fs = new FileStream(path))
{
    fs.Write(array, 0, array.length);
}


How To Read and Write BLOB Data by Using ADO.NET with Visual C# .NET


Try using an HttpHandler. Here is a nice tutorial on creating one. You would simply write the byte array to the response stream and post a link in your application similar to this one.

http://myserver/myhttphandler.ashx?mp3File=x
0

精彩评论

暂无评论...
验证码 换一张
取 消