Class AdaptiveImagesController
Used primarily for serving images and handle requests from the CMS UI, for example when searching for images through an image provider.
Inherited Members
Namespace: AdaptiveImages.Controllers
Assembly: AdaptiveImages.dll
Syntax
[Authorize(Roles = "CmsAdmins, AdaptiveImagesAdmins, CmsEditors, AdaptiveImagesEditors")]
[Route("AdaptiveImages")]
public class AdaptiveImagesController : Controller, IActionFilter, IAsyncActionFilter, IFilterMetadata, IDisposable
Constructors
AdaptiveImagesController(IAddonSettings, IContextModeResolver, IHttpContextAccessor, IImageCache)
Creates a new instance with required dependencies.
Declaration
public AdaptiveImagesController(IAddonSettings addonSettings, IContextModeResolver contextModeResolver, IHttpContextAccessor httpContextAccessor, IImageCache imageCache)
Parameters
Type | Name | Description |
---|---|---|
IAddonSettings | addonSettings | For example used to determine default breakpoints. |
IContextModeResolver | contextModeResolver | Used to determine whether request is in context of edit mode. |
IHttpContextAccessor | httpContextAccessor | Used to get details about the current HTTP context. |
IImageCache | imageCache | The service used for caching images. |
Methods
GetImageAsync(string, string, string, int?, int?, int?, int?, int?, int?, bool, int?, CancellationToken)
Serves an image, optionally cropped and/or scaled.
Declaration
[AllowAnonymous]
[Route("{providerName}/{*imageIdPath}")]
[HttpGet]
[HttpHead]
public Task<ActionResult> GetImageAsync(string providerName, string imageIdPath, string stamp, int? width = null, int? height = null, int? cropleft = null, int? croptop = null, int? cropright = null, int? cropbottom = null, bool thumbnail = false, int? quality = null, CancellationToken cancellationToken = default)
Parameters
Type | Name | Description |
---|---|---|
string | providerName | The image provider the image comes from. |
string | imageIdPath | The image id, optionally with second URL segment for a filename. |
string | stamp | Hash used to validate parameters, essentially to validate that image URL was generated on the server. |
int? | width | Desired width in pixels of the final image. |
int? | height | Desired height in pixels of the final image. |
int? | cropleft | Number of pixels to crop from the left of the image. |
int? | croptop | Number of pixels to crop from the top of the image. |
int? | cropright | The right-most crop X-coordinate. A value of 600 means the leftmost 600 pixels of the original image will remain, assuming a 'cropleft' value of 0. |
int? | cropbottom | The bottom crop Y-coordinate. A value of 600 means the top 600 pixels of the original image will remain, assuming a 'croptop' value of 0. |
bool | thumbnail | Whether the resulting image is intended for thumbnail use. Depending on the image provider this may affect image quality. |
int? | quality | A value of 0-100 to explicitly specify quality, i.e. level of compression. |
CancellationToken | cancellationToken |
Returns
Type | Description |
---|---|
Task<ActionResult> | Binary data for the image. |
Remarks
This endpoint does not require authentication.
Exceptions
Type | Condition |
---|---|
AdaptiveImagesException |
Search(SearchParameters)
Searches for images through an image provider.
Declaration
[ResponseCache(Duration = 300)]
[Route("search")]
[HttpPost]
public Task<ActionResult> Search(AdaptiveImagesController.SearchParameters parameters)
Parameters
Type | Name | Description |
---|---|---|
AdaptiveImagesController.SearchParameters | parameters | What to search for and through which image provider. |
Returns
Type | Description |
---|---|
Task<ActionResult> | Search result as JSON. |
Exceptions
Type | Condition |
---|---|
NotSupportedException |
Upload(IFormFile, ImageProviderAsset?, string[]?)
Used to upload an image to an image provider.
Declaration
[HttpPost]
[Route("upload")]
public Task<ActionResult> Upload(IFormFile imagefile, ImageProviderAsset? metadata = null, string[]? providerOptions = null)
Parameters
Type | Name | Description |
---|---|---|
IFormFile | imagefile | |
ImageProviderAsset | metadata | |
string[] | providerOptions |
Returns
Type | Description |
---|---|
Task<ActionResult> | Image metadata as JSON. |
Remarks
Specified image provider must support uploads.
Exceptions
Type | Condition |
---|---|
ArgumentException | |
NotSupportedException | |
Exception |