public static void RenderFile(FrontContext context, Models.CmsFile file) { string contentType; if (!string.IsNullOrEmpty(file.ContentType)) { contentType = file.ContentType; } else { contentType = IOHelper.MimeType(file.Name); } context.RenderContext.Response.ContentType = contentType; if (file.ContentBytes != null) { context.RenderContext.Response.Body = file.ContentBytes; } else if (!string.IsNullOrEmpty(file.ContentString)) { context.RenderContext.Response.Body = DataConstants.DefaultEncoding.GetBytes(file.ContentString); } // cache for font. if (contentType != null && contentType.ToLower().Contains("font")) { context.RenderContext.Response.Headers["Expires"] = DateTime.UtcNow.AddYears(1).ToString("r"); } }
public static void RenderFile(FrontContext context, Models.CmsFile file) { string contentType; if (!string.IsNullOrEmpty(file.ContentType)) { contentType = file.ContentType; } else { contentType = IOHelper.MimeType(file.Name); } context.RenderContext.Response.ContentType = contentType; if (file.ContentBytes != null) { context.RenderContext.Response.Body = file.ContentBytes; } else if (!string.IsNullOrEmpty(file.ContentString)) { context.RenderContext.Response.Body = DataConstants.DefaultEncoding.GetBytes(file.ContentString); } // cache for font. if (contentType != null) { if (contentType.ToLower().Contains("font")) { context.RenderContext.Response.Headers["Expires"] = DateTime.UtcNow.AddYears(1).ToString("r"); } else if (contentType.ToLower().Contains("image")) { context.RenderContext.Response.Headers.Add("Access-Control-Allow-Origin", "*"); context.RenderContext.Response.Headers.Add("Access-Control-Allow-Headers", "*"); if (context.RenderContext.WebSite.EnableImageBrowserCache) { if (context.RenderContext.WebSite.ImageCacheDays > 0) { context.RenderContext.Response.Headers["Expires"] = DateTime.UtcNow.AddDays(context.RenderContext.WebSite.ImageCacheDays).ToString("r"); } else { // double verify... var version = context.RenderContext.Request.GetValue("version"); if (!string.IsNullOrWhiteSpace(version)) { context.RenderContext.Response.Headers["Expires"] = DateTime.UtcNow.AddYears(1).ToString("r"); } } } } } }
public static void RenderFile(FrontContext context, Models.CmsFile file) { string contentType; if (!string.IsNullOrEmpty(file.ContentType)) { contentType = file.ContentType; } else { contentType = IOHelper.MimeType(file.Name); } context.RenderContext.Response.ContentType = contentType; if (file.ContentBytes != null) { context.RenderContext.Response.Body = file.ContentBytes; } else if (!string.IsNullOrEmpty(file.ContentString)) { context.RenderContext.Response.Body = DataConstants.DefaultEncoding.GetBytes(file.ContentString); } }
//file only contains column data. public static async Task RenderFile(FrontContext context, Models.CmsFile file) { var sitedb = context.WebSite.SiteDb(); string contentType = null; if (!string.IsNullOrEmpty(file.ContentType)) { contentType = file.ContentType; } else if (!string.IsNullOrWhiteSpace(file.Name)) { contentType = IOHelper.MimeType(file.Name); } if (string.IsNullOrWhiteSpace(contentType)) { if (context.Route != null) { contentType = IOHelper.MimeType(context.Route.Name); } } context.RenderContext.Response.ContentType = contentType; if (file.Size > BigSize) { var partinfo = sitedb.Files.Store.GetFieldPart(file.Id, nameof(file.ContentBytes)); context.RenderContext.Response.FilePart = partinfo; } else { // read whole content. CmsFile FileContent = null; if (file.ContentBytes == null) { FileContent = await sitedb.FilePool.GetAsync(file.Id); } else { FileContent = file; } if (FileContent.ContentBytes != null) { context.RenderContext.Response.Body = FileContent.ContentBytes; } else if (!string.IsNullOrEmpty(FileContent.ContentString)) { context.RenderContext.Response.Body = DataConstants.DefaultEncoding.GetBytes(FileContent.ContentString); } } // cache for font. if (contentType != null) { string lower = contentType.ToLower(); if (lower.Contains("font")) { VersionRenderer.FontVersion(context); } else if (lower.Contains("image")) { context.RenderContext.Response.Headers.Add("Access-Control-Allow-Origin", "*"); context.RenderContext.Response.Headers.Add("Access-Control-Allow-Headers", "*"); VersionRenderer.ImageVersion(context); } else if (lower.Contains("css")) { VersionRenderer.ScriptStyleVersion(context); } else if (lower.Contains("javascript")) { VersionRenderer.ScriptStyleVersion(context); } else if (lower.Contains("video")) { VersionRenderer.VideoVersion(context); } } }
//file only contains column data. public static async Task RenderFile(FrontContext context, Models.CmsFile file) { var sitedb = context.WebSite.SiteDb(); string contentType = null; if (!string.IsNullOrEmpty(file.ContentType)) { contentType = file.ContentType; } else if (!string.IsNullOrWhiteSpace(file.Name)) { contentType = IOHelper.MimeType(file.Name); } if (string.IsNullOrWhiteSpace(contentType)) { if (context.Route != null) { contentType = IOHelper.MimeType(context.Route.Name); } } context.RenderContext.Response.ContentType = contentType; if (file.Size > BigSize) { var partinfo = sitedb.Files.Store.GetFieldPart(file.Id, nameof(file.ContentBytes)); context.RenderContext.Response.FilePart = partinfo; } else { // read whole content. var FileContent = await sitedb.FilePool.GetAsync(file.Id); if (FileContent.ContentBytes != null) { context.RenderContext.Response.Body = FileContent.ContentBytes; } else if (!string.IsNullOrEmpty(FileContent.ContentString)) { context.RenderContext.Response.Body = DataConstants.DefaultEncoding.GetBytes(FileContent.ContentString); } } // cache for font. if (contentType != null) { if (contentType.ToLower().Contains("font")) { context.RenderContext.Response.Headers["Expires"] = DateTime.UtcNow.AddYears(1).ToString("r"); } else if (contentType.ToLower().Contains("image")) { context.RenderContext.Response.Headers.Add("Access-Control-Allow-Origin", "*"); context.RenderContext.Response.Headers.Add("Access-Control-Allow-Headers", "*"); if (context.RenderContext.WebSite.EnableImageBrowserCache) { if (context.RenderContext.WebSite.ImageCacheDays > 0) { context.RenderContext.Response.Headers["Expires"] = DateTime.UtcNow.AddDays(context.RenderContext.WebSite.ImageCacheDays).ToString("r"); } else { // double verify... var version = context.RenderContext.Request.GetValue("version"); if (!string.IsNullOrWhiteSpace(version)) { context.RenderContext.Response.Headers["Expires"] = DateTime.UtcNow.AddYears(1).ToString("r"); } } } } } }