Sling Mappings for DAM Assets | Community
Skip to main content
New Participant
October 16, 2015
Solved

Sling Mappings for DAM Assets

  • October 16, 2015
  • 4 replies
  • 1560 views

Hi All,

Is it possible to create Sling Rewrites for DAM asset paths?  For instance, I'd like to rewrite the path to all images in my html.  

 

By default the html looks like this:

<img src="/content/dam/products/shirt.jpg" />

 

But, I'd like to rewrite the path so it looks like this: 

<img src="/assets/products/shirt.jpg" />

 

I've added the following rule to the Resource Resolver Factory: 

/content/dam(.*)</asset$1

 

And included this as a Rewrite Element in the Link Checker Transformer: 

img:src

 

But the rewrite doesn't get applied at all.  I've tried editing the configurations in both via the Felix console and the repository.  But, no luck.  Does Sling apply to the DAM?  Or is there another preferred way to achieve the same result?

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Best answer by smacdonald2008

According to this sling doc:

http://sling.apache.org/documentation/bundles/output-rewriting-pipelines-org-apache-sling-rewriter.html 

Its output that is changed - not static DAM assets. 

4 replies

joerghoh
Employee
October 16, 2015

Hi,

Can you set the loglevel of the class com.day.cq.rewriter.linkchecker.impl.LinkCheckerTransformer to DEBUG and post the results?

kind regards,
Jörg

kvanstoneAuthor
New Participant
October 16, 2015

Hi Jörg, I've attached the log file.  I can see that links to html pages are being rewritten, but not links to DAM assets.  (<img> paths aren't being rewritten either).  According to the article smacdonald2008 posted above, "the CQ runtime system by default only uses the mapping rules for URLs associated with HTML pages. So links to things like PDFs stored in the DAM never get rewritten."

This seems to align with the behavior I'm seeing.  Do you agree / disagree?

By any chance is there an out-of-the-box feature available in AEM 6 that would handle this?  (We are currently on 5.6.1).

smacdonald2008
smacdonald2008Accepted solution
New Participant
October 16, 2015

According to this sling doc:

http://sling.apache.org/documentation/bundles/output-rewriting-pipelines-org-apache-sling-rewriter.html 

Its output that is changed - not static DAM assets. 

smacdonald2008
New Participant
October 16, 2015
You can write a custom link rewrite service. See this article for details: http://www.cqblueprints.com/tipsandtricks/serving-static-assets-alt-url.html