One way could be hook up an event handler to ContentRoute.CreatedVirtualPath which is raised when an url is generated. In the event handler you would like to determine if the url is to a resource from amazon S3 and if so replace the url with a CDN url. It could look something like:
public void ReplaceWithCdnUrl(object source, UrlBuilderEventArgs eventArgs)
{
//Check if routed content is a IBinaryStorable with a AmazonBlob, if so replace url with cdn blob uri
object contentReferenceObject;
if (eventArgs.RouteValues.TryGetValue(RoutingConstants.NodeKey, out contentReferenceObject))
{
ContentReference routedContentLink = contentReferenceObject as ContentReference;
if (!ContentReference.IsNullOrEmpty(routedContentLink))
{
var binaryContent = _contentLoader.Get<IContent>(routedContentLink) as IBinaryStorable;
if (binaryContent != null)
{
//Check that Everyone has Read access before switching to external url
ISecurable securable = binaryContent as ISecurable;
if (securable != null)
{
if ((securable.GetSecurityDescriptor().GetAccessLevel(PrincipalInfo.AnonymousPrincipal) & AccessLevel.Read) != AccessLevel.Read)
{
return;
}
}
var amazonBlob = binaryContent.BinaryData as AmazonBlob;
if (amazonBlob != null)
{
UrlBuilder cdnUrlBuilder = new UrlBuilder(<yourcdnhost from e.g. AppConfig>);
cdnUrlBuilder.Path = amazonBlob.ID.PathAndQuery;
eventArgs.UrlBuilder.Uri = cdnUrlBuilder.Uri;
}
}
}
}
}
I realize I'm late to this party, but we used this same code (for Azure BLOBs), which we found somewhere else. However, we found that it doesn't cover the thumbnails. If you do an "/image100" URL or something, there's no way to detect this and alter the URL to Azure.
We tried to do something similar. Even though we were able to get AWS Cloud Front CDN to serve content from S3 bucket we were unable to use friendly names of our images.
Firendly names are a requirement for SEO. So we ended up place the entire site behind cloud front.
I was wondering if anybody has been able to use EPiServer iwth either Azure or AWS CDN and still use friendly names for images?
Thanks
We tried to do something similar. Even though we were able to get AWS Cloud Front CDN to serve content from S3 bucket we were unable to use friendly names of our images.
Firendly names are a requirement for SEO. So we ended up place the entire site behind cloud front.
I was wondering if anybody has been able to use EPiServer iwth either Azure or AWS CDN and still use friendly names for images?
Thanks
Hi All,
Does anybody know how to use CloudFront CDN with EPiServer.Amazon.Blobs.AmazonBlobProvider?
I have uploaded file to S3 bucket using media assset manager .
When I drag&drop this file from assets to wysiwyg editor following link is generated <img src="/globalassets/file.jpg">
and it results in request to http://mybucket.s3.amazonaws.com/760e17737af54c658c0dcd63bb43a22e/e37a818079ef4281b43a0d28e12ffe1b.jpg
But I configured CloundFront CDN distribution for the bucket and want image to be downloaded from CDN - not directly from S3.
I remember that in Amazon VPP provider for EpiServer 7.0 is was a possibility to configure CDN so it generated links like this
<img src="http://1223124234.cloudfront.net/760e17737af54c658c0dcd63bb43a22e/e37a818079ef4281b43a0d28e12ffe1b.jpg">
Is it possible to do the same with new AmazonBlobProvider?