I work with a handler that presents multimedia content on a page.
The idea is that this handler accesses the file and determines the type using the extension and represents it, the problem is that most of the time the loader itself loads and the media does not display.
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 variable is valid filePath.
Could you help to prevent the handler from presenting multimedia content?
source
share