Externalizing links not working for assets

Avatar

Avatar

guruprasadb9915

Avatar

guruprasadb9915

guruprasadb9915

10-02-2021

Hi,

 

We have have implemented externalizer which works fine for all the links. However src property of images are not externalized. We do not conditionally externalize links.

 

For pages or image components that render within AEM it isn't much of a problem. However this becomes an issue with content fragments. The main reason we create a content fragment is to expose it to outside apps.

 

We have a content fragment which is exposed via the assets api to the react app. If we add and image into the Rich text editor, that image is not externalized making it totally useless to react app. 

 

Any thoughts on how this can be resolved?

Accepted Solutions (0)

Answers (1)

Answers (1)

Avatar

Avatar

bilala23933647

Avatar

bilala23933647

bilala23933647

10-02-2021

Hey guruprasadb9915, Have you tried creating a link transformer for this requirement? just target the <img> tag and update the <src> attribute and it will transform the src the way you want. Thanks!

guruprasadb9915

Hi bilala23933647,

Yes I have the link transformer configured. But I still do not see it transforming the img src even for html pages. Only the anchor tags are handled by Externalizer. Link transformer seems to be doing nothing.

 

link trans.JPG

 

However when I request the content fragment from Assets API, neither the anchor link nor the img src is externalised or re-written. This seems to be a fundametal requirement when we expect the content fragment to be consumed by other apps.

 

Also I am not a fan of using a JSON exporter (i mean mode.json). It just feels redundant to create a page for content fragment. I know I will run into caching issues (cant invalidate the cached content) if I dont create a page. What is the purpose of this asset API? It does not seem to help in any way.

bilala23933647

Hi @guruprasadb9915 , I don't understand why your default transformer is not coming to picture but if it still continues to do so, you can write a new custom LinkTransformer.

if (attributes.getIndex("src") == -1) {
attributes.addAttribute(StringUtils.EMPTY, "src", "src", "xs:string", "customSrc");
}

This will make sure that src is targeted while rendering the html.

guruprasadb9915
It will not solve the problem as link transformer or externalizer is not triggered when the request is made from assets api. I am not looking for a solution for HTML pages