string extension = Path.GetExtension(guid);
if (extension == ".gif")
{
//return the file from storage
// Get original file
FileContainer container = imageHandler.GetFile(guid);
var fileStream = container.Stream;
// return File(pageImage.Stream, GetContentType(_convertImageFileType));
byte[] Bytes = new byte[fileStream.Length];
fileStream.Read(Bytes, 0, Bytes.Length);
string contentDispositionString = "attachment; filename=\"" + displayName + "\"";
contentDispositionString = new ContentDisposition { FileName = displayName, Inline = true }.ToString();
HttpContext.Current.Response.ContentType = "image/jpeg";
HttpContext.Current.Response.AddHeader("Content-Disposition", contentDispositionString);
HttpContext.Current.Response.AddHeader("Content-Length", fileStream.Length.ToString());
try
{
HttpContext.Current.Response.OutputStream.Write(Bytes, 0, Bytes.Length);
HttpContext.Current.Response.Flush();
HttpContext.Current.Response.End();
}
catch (HttpException x)
{
// Ignore it.
}
}
else
{
//process file with ViewerImageHandler
List<PageImage> pageImages = imageHandler.GetPages(guid, imageOptions);
PageImage pageImage = pageImages.Single(_ => _.PageNumber == pageNumber);
var fileStream = pageImage.Stream;
// return File(pageImage.Stream, GetContentType(_convertImageFileType));
byte[] Bytes = new byte[fileStream.Length];
fileStream.Read(Bytes, 0, Bytes.Length);
string contentDispositionString = "attachment; filename=\"" + displayName + "\"";
contentDispositionString = new ContentDisposition { FileName = displayName, Inline = true }.ToString();
HttpContext.Current.Response.ContentType = "image/jpeg";
HttpContext.Current.Response.AddHeader("Content-Disposition", contentDispositionString);
HttpContext.Current.Response.AddHeader("Content-Length", fileStream.Length.ToString());
try
{
HttpContext.Current.Response.OutputStream.Write(Bytes, 0, Bytes.Length);
HttpContext.Current.Response.Flush();
HttpContext.Current.Response.End();
}
catch (HttpException x)
{
// Ignore it.
}
}