I am saving the uploaded file content as byte array with file extension in database. I wanted to use file result which returns any type of file. How can i achieve it ?
I tried with image file. Can i do like below code for all types ? will that works ?
public ActionResult GetAttachmentById(int AttachmentId)
{
try
{
byte[] AttachmentData = GetFromDatabase(AttachmentId);
string FileExtension = GetExtensionFromDatabase(AttachmentId);
return File(AttachmentData, FileExtension );
}
catch (Exception ex)
{
return File("", FileExtension);
}
}
You need to define the Mimetype, file name and extension dynamically.
Then return a File object from the action like this: