I am working with a handler that presents multimedia content in a page.
The idea is that this handler access the file and determine the type using the extension, and presenting it, the problem is that most of the times the handler itself gets downloaded and the multimedia is not presented.
Here is the code:
FileInfo file = new FileInfo(filePath);
byte[] bytes = new byte[file.Length];
using (FileStream fs = file.OpenRead())
{
fs.Read(bytes, 0, bytes.Length);
}
string extension = Path.GetExtension(filePath);
string mimeDeclaration;
if (".tif" == extension)
mimeDeclaration = "tiff";
string[] imagenes = new string[] {".jpg", ".jpeg", ".bmp", ".gif", ".png"};
if (imagenes.Any(x => x.Contains(extension)))
mimeDeclaration = extension.Substring(1);
else
mimeDeclaration = string.Empty;
context.Response.ClearContent();
context.Response.ClearHeaders();
context.Response.ContentType = "image/" + mimeDeclaration;
context.Response.BinaryWrite(bytes);
The filePath
variable is valid.
Could you help me avoid the handler not to present the multimedia content?