I'm trying to implement a copy function in one of my workflow process, however the assetCopy method isn't working.
This is how I initialized and called the assetManager obj using this API com.adobe.granite.asset.api.AssetManager:
ResourceResolver resourceResolver = resolverFactory.getAdministrativeResourceResolver(null);
AssetManager am = resourceResolver.adaptTo(AssetManager.class);
String assetPath = "/content/dam/somefile.pdf";
String copyPath = "/content/dam/html/copiedfile.pdf";
am.copyAsset(assetPath, copyPath);
I've verified it's initialized properly by using the assetExists method and everything seems to be fine so not sure what the problem here can be.
Thanks
Solved! Go to Solution.
Views
Replies
Total Likes
After working on this more - the issue was in the API docs. It should be made clear that to work with this API - you still need to open a Session and save the session once you are done.
Here is the correct code:
//Invoke the adaptTo method to create a Session used to create a QueryManager
ResourceResolver resourceResolver = resolverFactory.getAdministrativeResourceResolver(null);
//Use AssetManager to place the file into the AEM DAM
com.adobe.granite.asset.api.AssetManager assetManager = resourceResolver.adaptTo(com.adobe.granite.asset.api.AssetManager.class);
// to get an existing asset
//Asset asset = assetManager.getAsset("/content/dam/testfolder/somefile.pdf");
session = resourceResolver.adaptTo(Session.class);
String assetPath = "/content/dam/testfolder/somefile.pdf";
String copyPath = "/content/dam/testhtml/copieddoc.pdf";
assetManager.copyAsset(assetPath, copyPath);
log.info("Moved the ASSET! ");
// Log out
session.save();
session.logout();
Here is an AEM community artilce on this subject:
https://helpx.adobe.com/experience-manager/using/graniteAPI.html
Views
Replies
Total Likes
what result are you seeing -an exception, null object, etc ?
Views
Replies
Total Likes
After working on this more - the issue was in the API docs. It should be made clear that to work with this API - you still need to open a Session and save the session once you are done.
Here is the correct code:
//Invoke the adaptTo method to create a Session used to create a QueryManager
ResourceResolver resourceResolver = resolverFactory.getAdministrativeResourceResolver(null);
//Use AssetManager to place the file into the AEM DAM
com.adobe.granite.asset.api.AssetManager assetManager = resourceResolver.adaptTo(com.adobe.granite.asset.api.AssetManager.class);
// to get an existing asset
//Asset asset = assetManager.getAsset("/content/dam/testfolder/somefile.pdf");
session = resourceResolver.adaptTo(Session.class);
String assetPath = "/content/dam/testfolder/somefile.pdf";
String copyPath = "/content/dam/testhtml/copieddoc.pdf";
assetManager.copyAsset(assetPath, copyPath);
log.info("Moved the ASSET! ");
// Log out
session.save();
session.logout();
Here is an AEM community artilce on this subject:
https://helpx.adobe.com/experience-manager/using/graniteAPI.html
Views
Replies
Total Likes
No exceptions or errors
Views
Replies
Total Likes
Any help on this please?
Views
Replies
Total Likes
I will look into this code today and report back tomorrow. I will test it as well. What CQ version are you using?
Views
Replies
Total Likes
AEM 6.0, and I'm using the API associated with "com.adobe.granite.asset.api" not "com.day.cq.dam.api". The latter doesn't
have the copyAsset method.
Thanks
Views
Replies
Total Likes
Views
Likes
Replies
Views
Likes
Replies