Example #1
0
        public override void ExecuteResult(ControllerContext context)
        {
            HttpResponseBase response = context.HttpContext.Response;
            HttpRequestBase  request  = context.HttpContext.Request;

            if (!HttpCacheHelper.IsFileFromCache(File, request, response))
            {
                string fileName;
                string fileNameEncoded = HttpUtility.UrlEncode(File.Name);

                if (context.HttpContext.Request.UserAgent.Contains("MSIE")) // IE < 9 do not support RFC 6266 (RFC 2231/RFC 5987)
                {
                    fileName = "filename=\"" + fileNameEncoded + "\"";
                }
                else
                {
                    fileName = "filename*=UTF-8\'\'" + fileNameEncoded; // RFC 6266 (RFC 2231/RFC 5987)
                }
                string mime;
                string disposition;
                if (IsDownload)
                {
                    mime        = "application/octet-stream";
                    disposition = "attachment; " + fileName;
                }
                else
                {
                    mime        = Helper.GetMimeType(File);
                    disposition = (mime.Contains("image") || mime.Contains("text") || mime == "application/x-shockwave-flash" ? "inline; " : "attachment; ") + fileName;
                }

                response.ContentType = mime;
                response.AppendHeader("Content-Disposition", disposition);
                response.AppendHeader("Content-Location", File.Name);
                response.AppendHeader("Content-Transfer-Encoding", "binary");
                response.AppendHeader("Content-Length", File.Length.ToString());
                response.WriteFile(File.FullName);
                response.End();
                response.Flush();
            }
            else
            {
                response.ContentType = IsDownload ? "application/octet-stream" : Helper.GetMimeType(File);
                response.End();
            }
        }
Example #2
0
        public ActionResult GetThumbnail(HttpRequestBase request, HttpResponseBase response, string hash)
        {
            string thumbHash = hash;

            if (thumbHash != null)
            {
                FullPath path = _driver.ParsePath(thumbHash);
                if (!path.IsDirectoty && path.Root.CanCreateThumbnail(path.File))
                {
                    if (!HttpCacheHelper.IsFileFromCache(path.File, request, response))
                    {
                        ImageWithMime thumb = path.Root.GenerateThumbnail(path);
                        return(new FileStreamResult(thumb.ImageStream, thumb.Mime));
                    }
                    response.ContentType = Helper.GetMimeType(path.Root.PicturesEditor.ConvertThumbnailExtension(path.File.Extension));
                    response.End();
                }
            }
            return(new EmptyResult());
        }