Without knowing exact details of your implementation its difficult to say what the problem is, Im assuming you are using Content Providers and its an issue with the Routing if so maybe this thread can point you in the right direction : https://world.optimizely.com/forum/developer-forum/Developer-to-developer/Thread-Container/2017/12/custom-image-content-provider---image-doesn39t-render-in-edit-mode/
Thanks for the response Minesh Shah (Netcel).
I am using the content providers, the link which you refer i tried but didn't work. I am not able to implement routing in cms 12 inside the inaliazation module.
Sure Surjit Bharath
I coudn't posted the complete code since it will be more complex. I have just posted the important part of code.
Component
[Component]
public class CustomComponent : ComponentDefinitionBase
{
public CustomComponent()
: base("epi-cms/component/Media")
{
this.Title = CustomConstants.ProviderName;
this.Description = "Allows you to connect to Custom DAM for asset retrieval.";
this.Categories = new string[] { "content" };
this.PlugInAreas = new string[] { PlugInArea.AssetsDefaultGroup };
this.Settings.Add(new Setting("repositoryKey", CustomConstants.ProviderKey));
this.SortOrder = 900;
}
}
Inititialization
public void Initialize(InitializationEngine context)
{
var providerValues = new NameValueCollection();
providerValues.Add("entryPoint", AssetService.GetEntryPoint(CustomConstants.ProviderKey).ContentLink.ToString());
providerValues.Add("capabilities", "Create,Edit,Delete,Move,Copy,MultiLanguage,PageFolder,Search,Security,Wastebasket");
var providerManager = context.Locate.Advanced.GetInstance<IContentProviderManager>();
var provider = context.Locate.Advanced.GetInstance<ContentProvider>();
provider.Initialize(CustomConstants.ProviderKey, providerValues);
providerManager.ProviderMap.AddProvider(provider);
}
ContentProvider
protected override IContent LoadContent(ContentReference contentLink, ILanguageSelector languageSelector)
{
MappedIdentity mappedIdentity = identityMappingService.Get(contentLink);
if (mappedIdentity == null)
{
return null;
}
if (mappedIdentity.ExternalIdentifier.Segments.Length == 4)
{
var folderId = RemoveEndingSlash(mappedIdentity.ExternalIdentifier.Segments[1]);
var asset = AssetService.GetAssetByFolderId(folderId);
if (asset != null)
{
return CreateContentFolder(mappedIdentity, asset);
}
}
else if (mappedIdentity.ExternalIdentifier.Segments.Length == 5)
{
var folderId = RemoveEndingSlash(mappedIdentity.ExternalIdentifier.Segments[1]);
var ImageId = RemoveEndingSlash(mappedIdentity.ExternalIdentifier.Segments[2]);
var AssetData = AssetService.GetAssetImage(folderId, ImageId);
if (AssetData != null)
{
return CreateAsset(mappedIdentity, AssetData);
}
}
return null;
}
protected override IList<GetChildrenReferenceResult> LoadChildrenReferencesAndTypes(ContentReference contentLink, string languageID, out bool languageSpecific)
{
languageSpecific = false;
var childrenList = new List<GetChildrenReferenceResult>();
if (EntryPoint.CompareToIgnoreWorkID(contentLink))
{
if (AssetService.Asset.assets != null)
{
var filterRootFolder = AssetService.Asset.assets.Where(x => x.ParentId == "0").ToList();
foreach (var folder in filterRootFolder)
{
string uniquePath = string.Format("{0}/{1}/{2}", folder.FolderId, folder.FolderName, folder.ParentId);
childrenList.Add(new GetChildrenReferenceResult { ContentLink = identityMappingService.Get(MappedIdentity.ConstructExternalIdentifier(ProviderKey, uniquePath), true).ContentLink, IsLeafNode = false, ModelType = typeof(ContentFolder) });
}
}
return childrenList;
}
MappedIdentity mappedIdentity = identityMappingService.Get(contentLink);
if (mappedIdentity == null)
{
return null;
}
var folderId = RemoveEndingSlash(mappedIdentity.ExternalIdentifier.Segments[1]);
var assetlist = AssetService.GetAssetByParentId(folderId);
foreach (var asset in assetlist)
{
string uniquePath = string.Format("{0}/{1}/{2}", asset.FolderId, asset.FolderName, asset.ParentId);
var uri = MappedIdentity.ConstructExternalIdentifier(ProviderKey, uniquePath);
var mappedChild = identityMappingService.Get(uri, true);
childrenList.Add(new GetChildrenReferenceResult
{
ContentLink = mappedChild.ContentLink,
IsLeafNode = false,
ModelType = typeof(ContentFolder)
});
}
var assetImage = AssetService.GetAssetByFolderId(folderId);
if (assetImage != null)
{
if (assetImage.Images != null)
{
foreach (var image in assetImage.Images)
{
string uniquePath = string.Format("{0}/{1}/{2}/{3}", assetImage.FolderId,
image.ImageId, image.Name, assetImage.ParentId);
var uri = MappedIdentity.ConstructExternalIdentifier(ProviderKey, uniquePath);
var mappedImage = identityMappingService.Get(uri, true);
childrenList.Add(new GetChildrenReferenceResult
{
ContentLink = mappedImage.ContentLink,
IsLeafNode = true,
ModelType = typeof(AssetData)
});
}
}
}
return childrenList;
}
private IContent CreateContentFolder(MappedIdentity mappedIdentity, dynamic assetData)
{
if (assetData != null)
{
var content = CreateAndAssignIdentity(mappedIdentity, typeof(ContentFolder), assetData.FolderName);
return content;
}
return null;
}
private IContent CreateAssetData(MappedIdentity mappedIdentity, Type modelType, dynamic assetData)
{
if (assetData != null)
{
var contentMedia = CreateAndAssignIdentity(mappedIdentity, modelType, assetData.Name, assetData.Url);
return contentMedia;
}
return null;
}
public AssetData CreateAsset(MappedIdentity mappedIdentity, dynamic assetData)
{
if (assetData != null)
{
var contentMedia = CreateAssetData(mappedIdentity, typeof(CustomGenericFile), assetData) as AssetData;
contentMedia.ImageId = assetData.ImageId;
contentMedia.Url = assetData.Url;
contentMedia.ThumbnailUrl = assetData.ThumbnailUrl;
return contentMedia;
}
return null;
}
private IContent CreateAndAssignIdentity(MappedIdentity mappedIdentity, Type modelType, string name, string url = "")
{
var parentLink = EntryPoint;
if (modelType == typeof(CustomGenericFile))
{
var folderId = RemoveEndingSlash(mappedIdentity.ExternalIdentifier.Segments[1]);
var asset = AssetService.GetAssetByFolderId(folderId);
string uniquePath = string.Format("{0}/{1}/{2}", asset.FolderId, asset.FolderName, asset.ParentId);
var uri = MappedIdentity.ConstructExternalIdentifier(ProviderKey, uniquePath);
var mappedParentIdentity = identityMappingService.Get(uri, true);
parentLink = new ContentReference(mappedParentIdentity.ContentLink.ID, ProviderKey);
}
else if (modelType == typeof(ContentFolder))
{
var ParentId = RemoveEndingSlash(mappedIdentity.ExternalIdentifier.Segments[3]);
if (ParentId == "0")
{
parentLink = EntryPoint;
}
else
{
var asset = AssetService.GetAssetDataByParentId(ParentId);
string uniquePath = string.Format("{0}/{1}/{2}", asset.FolderId, asset.FolderName, asset.ParentId);
var uri = MappedIdentity.ConstructExternalIdentifier(ProviderKey, uniquePath);
var mappedParentIdentity = identityMappingService.Get(uri, true);
parentLink = new ContentReference(mappedParentIdentity.ContentLink.ID, ProviderKey);
}
}
// Set content type and content type Id.
var contentType = contentTypeRepository.Load(modelType);
var content = contentFactory.CreateContent(contentType);
content.ContentTypeID = contentType.ID;
content.ParentLink = parentLink;
content.ContentGuid = mappedIdentity.ContentGuid;
content.ContentLink = mappedIdentity.ContentLink;
content.Name = name;
(content as IRoutable).RouteSegment = url;
var securable = content as IContentSecurable;
securable.GetContentSecurityDescriptor().AddEntry(new AccessControlEntry(EveryoneRole.RoleName, AccessLevel.Read));
var versionable = content as IVersionable;
if (versionable != null)
{
versionable.Status = VersionStatus.Published;
}
var changeTrackable = content as IChangeTrackable;
if (changeTrackable != null)
{
changeTrackable.Changed = DateTime.Now;
}
return content;
}
Bit of a guess, but it looks like you are using the MediaData url field incorrectly
Content Providers are a means of serving and managing external content within the Optimizely Content Cloud UI. In the case of a DAM and files, the normal pattern would be to bring the file's blob / bytes into Optimizely and then serve the file directly from Optimizely. It looks as if you are trying to choose the file in the Optimizely UI and serve the file directly from the DAM.
The contentMedia.Url field that you are entering the absolute assetData.Url into is used by Optimzely to create a relative path based on the domain of your front-end. I think this is why you see this /en/customdam/https://my domain/cms/images/2RhY61HO4Jx8hdD9R7ecbE/?scale=2k.
Easiest way around this is to store the asset.url in a custom field on a MediaData item. You may have to create your own class/media type that inherits from MediaData.
You will have to consider some how you render out an image to make sure that the any Razor views know when rendering an image to use the url in your new custom field if it exists, and if not to resolve the image and image url. There are lots of ways to work arounf this and you will need to make sure the editor still correctly previews the image (as it will by default use the expected episerver url to the content)
Hi Team,
I have create the custom media tab and binding all the folders and images from external json file. As a editor when I am dragging any images from custom tab into the page . It's taking the tab reference. Suppose I dragged a image which url is https://my domain/cms/images/2RhY61HO4Jx8hdD9R7ecbE/?scale=2k .
In the page property value is displaying like /en/customdam/https://my domain/cms/images/2RhY61HO4Jx8hdD9R7ecbE/?scale=2k.
Another biggest Issue- When external json file is getting refreshed and if json file desn't contains the old images then page property data is also getting lost.
I am looking for a solution. Please help..!