Skip to main content
Oct 16, 2015 2:27 AM UTC
Solved

AssetManager copyAsset method not working

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

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
smacdonald2008
smacdonald2008Accepted solution
Level 10
Oct 16, 2015 2:27 AM UTC

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

6 replies

Oct 16, 2015 2:27 AM UTC

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

Translate
smacdonald2008
Level 10
Oct 16, 2015 2:27 AM UTC

I will look into this code today and report back tomorrow. I will test it as well. What CQ version are you using?

Translate
Oct 16, 2015 2:27 AM UTC

Any help on this please?

Translate
Oct 16, 2015 2:27 AM UTC

No exceptions or errors

Translate
smacdonald2008
smacdonald2008Accepted solution
Level 10
Oct 16, 2015 2:27 AM UTC

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

Translate
smacdonald2008
Level 10
Oct 16, 2015 2:27 AM UTC

what result are you seeing -an exception, null object, etc ? 

Translate