I have successfully done the upload bit - uploaded the MP3 files to my SQL Server, but I need help in downloading the files.... I use the following code to upload the MP3 file
public ActionResult Create([Bind(Include = "ID,Artist,Album")] TrackUpload trackUpload, HttpPostedFileBase upload)
{
try
{
if (ModelState.IsValid)
{
if (upload != null && upload.ContentLength > 0)
{
var song = new File
{
FileName = System.IO.Path.GetFileName(upload.FileName),
FileType = FileType.Songs,
ContentType = upload.ContentType
};
using (var reader = new System.IO.BinaryReader(upload.InputStream))
{
song.Content = reader.ReadBytes(upload.ContentLength);
}
trackUpload.Files = new List<File> { song };
}
db.TrackUploads.Add(trackUpload);
db.SaveChanges();
return RedirectToAction("Index");
}
}
catch (RetryLimitExceededException /* dex */)
{
ModelState.AddModelError("", "Cant save changes.");
}
return View(trackUpload);
}
It is working fine which meaning the file stores in Database, Now how do i download the MP3 file from sql db using entity framework