Our monthly Virtual Happy Hour is happening this week, Fri Feb 23!

Try our conversational search powered by Generative AI!

Amazon S3 blob provider and CloudFront CDN

Vote:
 

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?

 

#81571
Feb 19, 2014 16:05
Vote:
 

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;
                        }
                    }
                }
            }
        }

    

#81576
Feb 19, 2014 16:38
Vote:
 

Great! It works! Didn't expected such a quick response!

#81577
Feb 19, 2014 17:02
Vote:
 

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.

#144705
Feb 17, 2016 16:43
Vote:
 

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

#144718
Feb 18, 2016 5:55
Vote:
 

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

#144719
Feb 18, 2016 5:55
This topic was created over six months ago and has been resolved. If you have a similar question, please create a new topic and refer to this one.
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.