Expand my Community achievements bar.

Learn about Edge Delivery Services in upcoming GEM session
SOLVED

Programmatically change asset name

Avatar

Level 5

Is this possible?

Couldn't find any methods in the API to do so.

 

Thanks!

1 Accepted Solution

Avatar

Correct answer by
Level 10

Try calling the MoveAsset method that belongs to this API:

https://docs.adobe.com/docs/en/cq/5-6-1/javadoc/com/adobe/granite/asset/api/AssetManager.html#moveAs..., java.lang.String)

Parameters:
assetPath - Absolute path of the asset to be moved
destAbsPath - Absolute path at with asset is to be moved

for destAbsPath  - specify the new name of the Asset.

To learn how to use the granite AssetManager API - see this article: 

https://helpx.adobe.com/experience-manager/using/graniteAPI.html (tested on AEM 6)

View solution in original post

9 Replies

Avatar

Correct answer by
Level 10

Try calling the MoveAsset method that belongs to this API:

https://docs.adobe.com/docs/en/cq/5-6-1/javadoc/com/adobe/granite/asset/api/AssetManager.html#moveAs..., java.lang.String)

Parameters:
assetPath - Absolute path of the asset to be moved
destAbsPath - Absolute path at with asset is to be moved

for destAbsPath  - specify the new name of the Asset.

To learn how to use the granite AssetManager API - see this article: 

https://helpx.adobe.com/experience-manager/using/graniteAPI.html (tested on AEM 6)

Avatar

Level 5

smacdonald2008 wrote...

Try calling the MoveAsset method that belongs to this API:

https://docs.adobe.com/docs/en/cq/5-6-1/javadoc/com/adobe/granite/asset/api/AssetManager.html#moveAs..., java.lang.String)

Parameters:
assetPath - Absolute path of the asset to be moved
destAbsPath - Absolute path at with asset is to be moved

for destAbsPath  - specify the new name of the Asset.

To learn how to use the granite AssetManager API - see this article: 

https://helpx.adobe.com/experience-manager/using/graniteAPI.html (tested on AEM 6)

 


Thank you Scott

Avatar

Administrator

Reference link to show one more use of AssetManager :- https://helpx.adobe.com/experience-manager/using/uploading-files-aem1.html

Thanks and Regards

Kautuk Sahni



Kautuk Sahni

Avatar

Level 3

smacdonald2008 Do AssetManager.moveAsset() method update the asset references as well in all the content or do we need to specifically handle it by writing custom code? When using "Move" option from author instance in Assets, it does update the content references of that particular asset which is moved, so wanted to confirm does API handle it automatically as well?

Avatar

Level 10

If you mean does it update in all pages referencing it - the answer is no. That is --  if you have a page referencing an asset in the DAM and you change the name - the reference in the page is not updated,

Avatar

Level 3

I am actually trying to figure what AEM uses internally when "Move" option is used from Assets UI. When the author Move an asset from Assets UI to a new destination, then all the pages where that asset was referenced, are automatically updated by AEM with the new destination path of the Asset. I need to do this Move from through a script, so thought of confirming if any API is there, which does update the references automatically or will I have to run queries to find all references and then update those references manually.

Avatar

Level 2

You can use CopyMoveCommandBuilder.java from package "com.day.cq.wcm.command.api" on 6.4.

e.g. :

@Reference
CommandBuilderFactory commandBuilderFactory;

CopyMoveCommandBuilder copyMoveCommandBuilder= commandBuilderFactory.createCommandBuilder(CopyMoveCommandBuilder.class).withCopy(false);

CopyMoveCommandPathArgument copyMoveCmdPathArg =

  (CopyMoveCommandPathArgument) copyMoveCommandBuilder.createPathArgumentBuilder()

  .withSrcPath(srcPath)

  .withDstPath(dstPath)

  .withAdjustRefPaths(adjustRefs)

  .withPublishPaths(publishRefs)

  .build();
   copyMoveCommandBuilder.withResourceResolver(resolver)

  .withAssetReferenceResolver(assetRefResolver)

  .withRetrieveAllRefs(true).withShallow(true)

  .withCheckIntegrity(true).withBeforeName(before)

  .withPathArgument(copyMoveCmdPathArg);
}

Command cmd = copyMoveCommandBuilder.build();
CopyMoveCommandResult result = (CopyMoveCommandResult)cmd.execute();

You need collect all the references and provide to this.

Avatar

Level 1

asset reference resolver is null and 

throws exception in commandbuilder 

Avatar

Level 1

Is there a solution to this? 

@smacdonald2008 

All the links are expired. Is there an endpoint in the HTTP API to change asset name? Or is it possible to access the granite AssetManager API via things like postman?