Erasing Blobs

Vote:
 

Hi

We have an issue regarding diskstorage on our webbserver. 

We have an importjobb which imports files from disk to EPiServer as GenericMedia. This importjob runs quit frequently and we would like to erase Previous versions of the blobs from disk.

The problem is that all of the blobs in the blobscontainer are not erased!? When running the code in an Alloy CMS 9.6 it works.

At the customers produktionenvironment we had the default uiMaxVersions set to 20 but since a month ago we decreased it to 4. I have noticed that this settings only is a UI setting, there will be a new blob for every version of the file dispite what is set for uiMaxVersions.

The code running for the job look like this:

private static List ProcessFiles(IContentRepository contentRepository, IContentVersionRepository versionRepository, IEnumerable genericFiles, List blobsDeleted)
{
foreach (var file in genericFiles)
{
if (file is GenericMedia)
{
var versionList = versionRepository.List(file.ContentLink);
foreach (var version in versionList)
{
if (version.Status.ToString() == "PreviouslyPublished")
{
try
{
//Getta en GenericFileVersion from version
var versionGenericFile = contentRepository.Get(version.ContentLink).CreateWritableClone() as GenericMedia;
BlobFactory.Instance.Delete(versionGenericFile.BinaryData.ID);
DataFactory.Instance.DeleteVersion(versionGenericFile.ContentLink, EPiServer.Security.AccessLevel.NoAccess);
blobsDeleted.Add(versionGenericFile.Name);
}
catch (Exception e)
{
var exception = e.Message;
if (e.InnerException != null)
exception = e.InnerException.ToString();
continue;
}
}
}
}
}
return blobsDeleted;
}

Is there any other way to delete all provious versions for a file?

#144744
Feb 18, 2016 11:44
Vote:
 

If you want to delete all blobs that is related to a content item then you can use 

                //Prefer constructor injection if possible 
                var blobFactory = ServiceLocator.Current.GetInstance<BlobFactory>();
                blobFactory.Delete(Blob.GetContainerIdentifier(content.ContentGuid));

Note however that if you then go back to a previous version of the content then the associated blob with that version will not exist.

#144772
Feb 18, 2016 15:32
Vote:
 

Thanks Björn.

My intention is to have the Published version of each GenericMedia (file) to remain.

Have you any idea on how your approach towards creating blobs on disk in EPiServer is to work.

  • Are there any settings possible to configure on how many blobs (versions) should be allowed? (If uiMaxVersion=4 it doesn't matter there will be hundreds of blobs/versions of the same file/content.)
  • For a GenericFile, will all versions/blobs remain in the same blobContainer(diskfolder)?
#144774
Feb 18, 2016 15:48
Vote:
 

I thought you had a scenario where you is about to publish a new version, then my thought you could first remove every existing blob and then publish the new one (which leaves you with one). Otherwise if you want more control you can stick with your previously suggested code.

#144804
Feb 19, 2016 9:05
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.