Try our conversational search powered by Generative AI!

Removing assets from CDN

Vote:
 

Hi!

I have some content which I wanna remove (it will not be used on any pages etc) from CDN. Is it possible to remove those images through cms panel or at least from code? Moving items to trash (and empty trash) not removing items from CDN.

Episerver v9 here

CDN: CloudFront (Amazon) with S3 bucket

#181327
Edited, Aug 16, 2017 13:17
Vote:
 

Which CDN are you using?

/K

#181329
Aug 16, 2017 13:35
Vote:
 

Oh... forgot to write it under epi version. CloudFront (Amazon) with S3 bucket.

Will edit main post to include this info there too

#181330
Edited, Aug 16, 2017 13:42
Vote:
 

Yes, you want to call the CloudFront API when the file is changed somehow:

public class WebInit : EPiServer.Framework.IInitializableModule
    {
        public void Initialize(EPiServer.Framework.Initialization.InitializationEngine context)
        {
           
            if (Utilities.IsProdServer) //only in production
            {
                DataFactory.Instance.SavedContent += PurgeContent;
                DataFactory.Instance.MovedContent += PurgeContent;
                DataFactory.Instance.DeletedContent += PurgeContent;
            }
        }

 private void PurgeContent(object sender, ContentEventArgs e)
        {
            var cdnPurgeContent = false;

            bool.TryParse(ConfigurationManager.AppSettings["CDNPurgeContent"], out cdnPurgeContent); // a flag in web.config, not in dev or test

            if (e != null && cdnPurgeContent)
            {

                if (e.Content is MediaData) // here only media
                {
                    //Send to CDN
                    try
                    {
                        string purge_pattern = e.Content.Name;

                        PurgeCDN(UrlResolver.Current.GetUrl(e.Content.ContentLink));
                    }
                    catch (Exception ex)
                    {

                      //Log  Utilities.Instance.Logger("Error PurgeContent, purge against CDN: ", ex);

                    }
                }
            }
        }

Then build your "PurgeCDN" against the API of your CDN, it probably looks something like this:

                        var values = new NameValueCollection();
                        values["site_id"] = siteid; //iggesund
                        values["api_id"] = api_id;
                        values["api_key"] = api_key;
                        values["purge_pattern"] = url;

                        var response = client.UploadValues(CDN_URL, values);

                        var responseString = Encoding.Default.GetString(response);
#181411
Aug 18, 2017 8:45
Vote:
 

If you are using some custom blob provider than this can be managed from blob provider also. What blob provider are you using?

#181414
Aug 18, 2017 10:21
Vote:
 

I'm using Blob provider for AWS built in EpiServer.

#181416
Aug 18, 2017 10:36
Vote:
 

By disassembling episerver.amazo.9.2.0, I can see method implementation of Amazon Blob provider, where _StorageClient is IAmazonS3

public override void Delete(Uri id)
{
Blob.ValidateIdentifier(id, new bool?());
this._storageClient.DeleteObject(this.ClientConfiguration.BucketName, AmazonBlob.ConvertToKey(id));
}

On Clearing the trash This method should be called and delete the image from Amazon S3 or this may be calling on running remove abodoned blobs job.

Try once running the Job "Remove abandoned blobs" from admin also, does it clear your blobs? 

#181419
Aug 18, 2017 11:42
* 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.