Last active
March 8, 2017 00:17
-
-
Save CameronWills/bcaf9be253ec8fe127226fc0d33ef810 to your computer and use it in GitHub Desktop.
Implementation of ImageProcessor's IImageService interface for EpiServer - Retrieves EpiServer blobs for processing by ImageProcessor
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/// <summary> | |
/// EpiServer implementation of an ImageProcessor IImageService - provides the episerver image blobs to ImageProcessor for resizing etc. | |
/// </summary> | |
public class EpiServerImageService : IImageService | |
{ | |
/// <summary> | |
/// Gets or sets the prefix for the given implementation. | |
/// <remarks> | |
/// This value is used as a prefix for any image requests that should use this service. | |
/// </remarks> | |
/// </summary> | |
public string Prefix { get; set; } = string.Empty; | |
/// <summary> | |
/// Gets a value indicating whether the image service requests files from | |
/// the locally based file system. | |
/// </summary> | |
public bool IsFileLocalService => false; | |
/// <summary> | |
/// Gets or sets any additional settings required by the service. | |
/// </summary> | |
public Dictionary<string, string> Settings { get; set; } = new Dictionary<string, string>(); | |
/// <summary> | |
/// Gets or sets the white list of <see cref="System.Uri"/>. | |
/// </summary> | |
public Uri[] WhiteList { get; set; } | |
/// <summary> | |
/// Gets a value indicating whether the current request passes sanitizing rules. | |
/// </summary> | |
/// <param name="path"> | |
/// The image path. | |
/// </param> | |
/// <returns> | |
/// <c>True</c> if the request is valid; otherwise, <c>False</c>. | |
/// </returns> | |
public bool IsValidRequest(string path) | |
{ | |
return ImageHelpers.IsValidImageExtension(path); | |
} | |
/// <summary> | |
/// Gets the image using the given identifier. | |
/// </summary> | |
/// <param name="id"> | |
/// The value identifying the image to fetch. | |
/// </param> | |
/// <returns> | |
/// The <see cref="System.Byte"/> array containing the image data. | |
/// </returns> | |
public Task<byte[]> GetImage(object id) | |
{ | |
var helper = ServiceLocator.Current.GetInstance<IContentRouteHelper>(); | |
var content = helper?.Content; | |
if (content != null && content.QueryDistinctAccess(AccessLevel.Read)) | |
{ | |
var binary = content as IBinaryStorable; | |
if (binary != null) | |
return Task.FromResult(binary.BinaryData.ReadAllBytes()); | |
} | |
return Task.FromResult<byte[]>(null); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment