c# - Handler (MIME) for multimedia content not working -
i working handler presents multimedia content in page.
the idea handler access file , determine type using extension, , presenting it, problem of times handler gets downloaded , multimedia not presented.
here 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 valid.
could me avoid handler not present multimedia content?
i think now, when mimedeclaration empty or wrong don't image download.
this occurs in code because mime types images aren't always "image/" plus file extension:
context.response.contenttype = "image/" + mimedeclaration;
eg .jpg image it's
image/jpeg
otherwise it's because it's tiff image in case else clause setting mimedeclaration
empty string.
tip: detecting mime types file extension less ideal, check way here: alternative findmimefromdata method in urlmon.dll 1 has more mime types
Comments
Post a Comment