Image URL in Grid Not Respecting Customized IMediaUrlProvider
Hi, All:
Issue Description:
We are using customized IMediaUrlProvider. Implementation attached below.
We have an issue during embed image directly into Grid.
This issue is about the URL of embeded image.
When embed image directly in grid, the URL of the image not respect the value generated by our customized IMediaUrlProvider
Here's our investigation:
The URL() method will respect the customized IMediaUrlProvider in cshtml file.
But Model.value.image in here is a string, won't respect customized IMediaUrlProvider.
We've found that Media.cshtml is for rendering images in grid.
Could you please give a help, help us finding a correct way to use CDN link when visiting a image in page?
We have already configured saving images to CDN (Azure Blob). We only want to render correct image URL to page (Using link to CDN)
Implementation of customized IMediaUrlProvider:
using System;
using System.Configuration;
using Umbraco.Core.Models.PublishedContent;
using Umbraco.Core.PropertyEditors;
using Umbraco.Web;
using Umbraco.Web.Routing;
namespace UmbracoCMS.App_Code.GrapeCityMediaHandler
{
public class GrapeCityMediaProvider : DefaultMediaUrlProvider
{
public GrapeCityMediaProvider(PropertyEditorCollection propertyEditors) :
base(propertyEditors)
{
}
private static readonly string CDNLink = ConfigurationManager.AppSettings["azureCDN:CDNLink"];
private static readonly string CDNContainerName = ConfigurationManager.AppSettings["AzureBlobFileSystem.ContainerName:media"];
public override UrlInfo GetMediaUrl(UmbracoContext umbracoContext, IPublishedContent content, string propertyAlias,
UrlMode mode, string culture, Uri current)
{
var mediaUrl = base.GetMediaUrl(umbracoContext, content, propertyAlias, UrlMode.Relative, culture, current);
if (mediaUrl == null)
return null;
if (mediaUrl.IsUrl == false)
return mediaUrl;
if (!mediaUrl.Text.StartsWith("/media/"))
{
return mediaUrl;
}
if (string.IsNullOrEmpty(CDNLink) || string.IsNullOrEmpty(CDNContainerName))
{
return mediaUrl;
}
var mediaPath = mediaUrl.Text.Replace("/media/", "/" + CDNContainerName + "/");
var cdnUrl = new Uri(new Uri(CDNLink), mediaPath).ToString();
return UrlInfo.Url(cdnUrl, culture);
}
}
}
Implementation of IUserComposer:
using Umbraco.Core.Composing;
using Umbraco.Web;
namespace UmbracoCMS.App_Code.GrapeCityMediaHandler
{
public class GrapeCityComposer : IUserComposer
{
public void Compose(Composition composition)
{
composition
.MediaUrlProviders()
.Insert<GrapeCityMediaProvider>();
}
}
}
Normally with a CDN + Azure implementation, the first request for the image is via the CDN url
if the image is already in the CDN it's returned from the CDN, Umbraco doesn't see the request.
Now if you have Image Processor configured with it's cache also in blob storage... then Image Processor will look for a cached version of the processed image in it's cache storage area...
... if not, Image Processor will process the image with any querystring parameters and return the processed image to the CDN with direction to the cached storage location...
So there is overhead on the first request but superfast thereafter...
(Also,The Azure blob cache setup has a setting called StreamCachedImage check that too)
Image URL in Grid Not Respecting Customized IMediaUrlProvider
Hi, All:
Issue Description:
We are using customized
IMediaUrlProvider
. Implementation attached below.We have an issue during embed image directly into Grid.
This issue is about the URL of embeded image.
When embed image directly in grid, the URL of the image not respect the value generated by our customized
IMediaUrlProvider
Here's our investigation:
The URL() method will respect the customized
IMediaUrlProvider
in cshtml file.But
Model.value.image
in here is a string, won't respect customizedIMediaUrlProvider
.We've found that
Media.cshtml
is for rendering images in grid.Could you please give a help, help us finding a correct way to use CDN link when visiting a image in page?
We have already configured saving images to CDN (Azure Blob). We only want to render correct image URL to page (Using link to CDN)
Implementation of customized
IMediaUrlProvider
:Implementation of
IUserComposer
:Thanks for you excellent product!
Cary
Hello Cary,
Normally with a CDN + Azure implementation, the first request for the image is via the CDN url
if the image is already in the CDN it's returned from the CDN, Umbraco doesn't see the request. Now if you have Image Processor configured with it's cache also in blob storage... then Image Processor will look for a cached version of the processed image in it's cache storage area... ... if not, Image Processor will process the image with any querystring parameters and return the processed image to the CDN with direction to the cached storage location... So there is overhead on the first request but superfast thereafter... (Also,The Azure blob cache setup has a setting called StreamCachedImage check that too)
Go through this useful links if you haven't :- https://our.umbraco.com/packages/developer-tools/azure-cdn-toolkit-for-umbraco/ https://imageprocessor.org/imageprocessor-web/plugins/azure-blob-cache/
is working on a reply...