Expand my Community achievements bar.

Don’t miss the AEM Skill Exchange in SF on Nov 14—hear from industry leaders, learn best practices, and enhance your AEM strategy with practical tips.
SOLVED

Custom Metadata population on asset upload

Avatar

Level 3

I have a requirement of setting current logged in user's ID as value for a custom metadata field once I upload an asset in AEM DAM. eg. I logged in as admin,then "admin" need to be stored as value for a custom metadata field name "Owner'. How I can achieve it?

Thanks LM

1 Accepted Solution

Avatar

Correct answer by
Level 10

Write a custom DAM handler that is called when an asset is uploaded:

https://helpx.adobe.com/experience-manager/using/damhandler.html

You need to read the user id using the User management API:

http://jackrabbit.apache.org/api/2.0/org/apache/jackrabbit/api/security/user/UserManager.html

You can get current user:

Session session = resourceResolver.adaptTo(Session.class);
    UserManager userManager = resourceResolver.adaptTo(UserManager.class);
    /* to get the current user */
    Authorizable auth = userManager.getAuthorizable(session.getUserID());

Get the id and set the asset using AssetManger API. 

View solution in original post

1 Reply

Avatar

Correct answer by
Level 10

Write a custom DAM handler that is called when an asset is uploaded:

https://helpx.adobe.com/experience-manager/using/damhandler.html

You need to read the user id using the User management API:

http://jackrabbit.apache.org/api/2.0/org/apache/jackrabbit/api/security/user/UserManager.html

You can get current user:

Session session = resourceResolver.adaptTo(Session.class);
    UserManager userManager = resourceResolver.adaptTo(UserManager.class);
    /* to get the current user */
    Authorizable auth = userManager.getAuthorizable(session.getUserID());

Get the id and set the asset using AssetManger API.