What API and which copy() method I can use to copy creating version if exist? | Community
Skip to main content
Level 2
October 16, 2015
Solved

What API and which copy() method I can use to copy creating version if exist?

  • October 16, 2015
  • 2 replies
  • 2020 views

What API and which copy() method I can use to copy creating version if exist?

 

I am trying with API to copy asset from one to another DAM place and I want if there it already exist with same name etc, should create a version and copy new asset as new version.

 

Rohan.

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Best answer by rohan_raj1

Thanks Vasim, but I asked for copy method from one to another place while copying. But came across following by createAsset method taking source Assets InputStream.

                                InputStream stream =  asset.getRendition("original").getStream();
                                String mimetype= asset.getMimeType();
                                Asset desAsset=assetManager.createAsset(destinationFolderPath, stream, mimetype, true);                               
                                jcrSession.save();

I got the answer here is the method in com.day.cq.dam.api.AssetManager class, we created asset using createAsset(String path, InputStream is, String mimeType, boolean doSave) 

Creates a new asset at the given path. If an asset already exists at the given path, its original rendition is updated instead of creating a new asset.

https://docs.adobe.com/docs/en/aem/6-0/develop/ref/javadoc/com/day/cq/dam/api/AssetManager.html#createAsset(java.lang.String, java.io.InputStream, java.lang.String, boolean) 

Rohan.

2 replies

vasimakram
Level 4
October 16, 2015

For creating version you can use com.day.cq.dam.api.Asset api.

you can use following code

Resource assetRes = resourceResolverFactory.getResource(/content/dam/img_1);

Asset asset=assetRes.adaptTo(Asset.class);

asset.createRevision("label","comment");

 

once go through it https://docs.adobe.com/docs/en/cq/5-6-1/javadoc/com/day/cq/dam/api/Asset.html#createRevision(java.lang.String, java.lang.String)

rohan_raj1AuthorAccepted solution
Level 2
October 16, 2015

Thanks Vasim, but I asked for copy method from one to another place while copying. But came across following by createAsset method taking source Assets InputStream.

                                InputStream stream =  asset.getRendition("original").getStream();
                                String mimetype= asset.getMimeType();
                                Asset desAsset=assetManager.createAsset(destinationFolderPath, stream, mimetype, true);                               
                                jcrSession.save();

I got the answer here is the method in com.day.cq.dam.api.AssetManager class, we created asset using createAsset(String path, InputStream is, String mimeType, boolean doSave) 

Creates a new asset at the given path. If an asset already exists at the given path, its original rendition is updated instead of creating a new asset.

https://docs.adobe.com/docs/en/aem/6-0/develop/ref/javadoc/com/day/cq/dam/api/AssetManager.html#createAsset(java.lang.String, java.io.InputStream, java.lang.String, boolean) 

Rohan.