I have created an ashx handler to render image thumbnails from images in a mysql database. If a file name is passed through querystring, the content disposition filename is set (when user clicks "save as..." the filename appears). The images appear properly and the filename appears when user selects "save as..." but the filetype is listed as unknown and the file that downloads has no type.
I have tried adding ".jpg" to the end of the filename in content disposition for lack of anything else to try, but this made every image download as untitled.bmp.
byte[] imageData = null;
Image outputImage = null;
if (!String.IsNullOrEmpty(HttpContext.Current.Request.QueryString["pictureid"]))
pictureId = SafeConvert.ToInt(HttpContext.Current.Request.QueryString["pictureid"].Trim());
if (pictureId > -1)
{
if (!String.IsNullOrEmpty(fileName))
HttpContext.Current.Response.AppendHeader("Content-Disposition", "filename=" + fileName + ";");
imageData = new OHTManager().GetOrnamentImage(pictureId);
context.Response.ContentType = "text/jpeg";
context.Response.BinaryWrite(imageData);
}
else
{
throw new Exception("No image could be produced;");
}