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?
+5
A:
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?
Yves M.
2010-08-19 11:55:20
Agreed, large binary objects have no place in a database.
DavidGouge
2010-08-19 11:57:38
If it's SQL Server version >2008 you can take advantage of the filestream type.
Carles
2010-08-19 12:11:48
@Carles: true but still not an optimal version. Storing the files in a filesystem has also the advantage, that you can use indexing on the mp3 tags to let the user search for it.
Yves M.
2010-08-19 12:20:59
A:
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
Steve Danner
2010-08-19 13:06:51
That's the easy part. The difficult part is getting it to stream in the browser. Images are a different story.
Josh Stodola
2010-08-19 15:41:12
+1
A:
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);
}
Russ
2010-08-19 13:08:56
but where should i show the link and how should i show it using a data grid or anything else??? i don't know how to do at all..
Leema
2010-08-20 04:37:29