Unfortunately, the extension of assets is part of the node name in AEM. A sample geometrixx asset is stored as node “GeoCube_Datasheet.pdf” under /content/dam/geometrixx/documents .
When we try to access this with a selector /content/dam/geometrixx/documents/GeoCube_Datasheet.secure.pdf, the resource cannot be resolved, resulting in a 404.
After checking the Sling source code, we’ve found a way to get to the document with the selector: add all the selectors after the extension, and then add extension .res.
Why? that’s quite complicated:
adding the selectors after the original extension makes sure that the resource is actually found during resource resolution
rendering of resources needs to be done by the org.apache.sling.servlets.get.impl.helpers.StreamRendererServlet, but the servlet only accepts resources without an extension or with .res
But our troubles are not quite over yet: If we render this as a .res resource, Apache will serve this as content-type application/x‐dtbresource+xml
The following rewrite rule should take care of that for pdf documents:
RewriteRule ^/content/dam/(.*).secure.pdf /content/dam/$1.pdf.secure.res [PT,L,T=application/pdf]
With this rewrite rule, the asset is actually available for end users at the desired url /content/dam/geometrixx/documents/GeoCube_Datasheet.secure.pdf, hiding the .res extension workaround from the end user.
No comments:
Post a Comment
If you have any doubts or questions, please let us know.