Your achievements

Level 1

0% to

Level 2

Tip /
Sign in

Sign in to Community

to gain points, level up, and earn exciting badges like the new
BedrockMission!

Learn more

View all

Sign in to view all badges

SOLVED

Programmatically change asset name

TheBigRed
Level 4
Level 4

Is this possible?

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

 

Thanks!

1 Accepted Solution
smacdonald2008
Correct answer by
Level 10
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

8 Replies
smacdonald2008
Correct answer by
Level 10
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

TheBigRed
Level 4
Level 4

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

kautuk_sahni
Community Manager
Community Manager

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

gauravs23
Level 2
Level 2

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?

smacdonald2008
Level 10
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,

gauravs23
Level 2
Level 2

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.

indra_kumarg290
Level 2
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.

Vinitb
Level 1
Level 1

asset reference resolver is null and 

throws exception in commandbuilder