Leema
Leema

Reputation: 97

Retrieve mp3 file from database

I have a question regarding 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?

Upvotes: 0

Views: 2224

Answers (4)

Russ
Russ

Reputation: 4163

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);
}

Upvotes: 1

Steve Danner
Steve Danner

Reputation: 22158

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

Upvotes: 0

Yves M.
Yves M.

Reputation: 3318

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?

Upvotes: 5

Related Questions