Expand my Community achievements bar.

Don’t miss the AEM Skill Exchange in SF on Nov 14—hear from industry leaders, learn best practices, and enhance your AEM strategy with practical tips.
SOLVED

Accessing predecessor binary in DAM with URL without restoring

Avatar

Level 1

Hi,

Is it possible to access/download a previous version of a file in CQ5.4 DAM without first restoring the file with a URL?

Something like: /content/dam/photos/image1.tif/jcr:version/1.0/jcr:frozenNode/jcr:content/renditions/original/jcr:content/jcr:data

We need to extract older versions of images for reprint of legacy publications.

Thanks in advance,

Charles

1 Accepted Solution

Avatar

Correct answer by
Level 10

In the CQ doc topic:  -- http://wem.help.adobe.com/enterprise/en_US/10-0/wem/dam/cq5_dam_version_management.html -- it states that all versions of an asset are store. Therefore because it is still stored -- you can retrieve the asset using the Query Builder API. This API lets you search and get assets in the CQ DAM. 

Here is Query Builder API code that searches the CQ DAM and gets assets.

In your situation- make sure that you setup the search in order to get the correct digital asset version.
 

<%@include file="/libs/foundation/global.jsp"%>

<%@page session="false" %>

<%@page import="com.day.cq.tagging.*,com.day.cq.wcm.api.*"%>

 

<%@ page import="java.util.*,

    javax.jcr.*,

    org.apache.sling.api.resource.*,

    org.apache.sling.api.scripting.*,

    org.apache.sling.jcr.api.*,

    com.day.cq.search.*,

    com.day.cq.search.result.*"

 

 %>

 

<%@page import="com.day.cq.dam.api.Asset"%>

 

<%

SlingRepository slingRep = sling.getService(SlingRepository.class);

Session session = slingRep.loginAdministrative(null);

QueryBuilder qb ;

Map<String, String> map = new HashMap<String,String>();

map.put("type", "dam.Asset");

map.put("property", "jcr:content/metadata/dc:format");

map.put("property.value", "image/jpeg");

qb=resource.getResourceResolver().adaptTo(QueryBuilder.class);

Query query = qb.createQuery(PredicateGroup.create(map), session);

 

SearchResult sr= query.getResult();

String assetPath=null;

 

 // iterating over the results

  for (Hit hit : sr.getHits()) {

      String path = hit.getPath();

      Resource rs = resourceResolver.getResource(path);

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

     assetPath = asset.getPath();

%>

<img src = "<%= asset.getRendition("cq5dam.thumbnail.140.100.png").getPath()%>" ></img>

<%

}

%>

View solution in original post

1 Reply

Avatar

Correct answer by
Level 10

In the CQ doc topic:  -- http://wem.help.adobe.com/enterprise/en_US/10-0/wem/dam/cq5_dam_version_management.html -- it states that all versions of an asset are store. Therefore because it is still stored -- you can retrieve the asset using the Query Builder API. This API lets you search and get assets in the CQ DAM. 

Here is Query Builder API code that searches the CQ DAM and gets assets.

In your situation- make sure that you setup the search in order to get the correct digital asset version.
 

<%@include file="/libs/foundation/global.jsp"%>

<%@page session="false" %>

<%@page import="com.day.cq.tagging.*,com.day.cq.wcm.api.*"%>

 

<%@ page import="java.util.*,

    javax.jcr.*,

    org.apache.sling.api.resource.*,

    org.apache.sling.api.scripting.*,

    org.apache.sling.jcr.api.*,

    com.day.cq.search.*,

    com.day.cq.search.result.*"

 

 %>

 

<%@page import="com.day.cq.dam.api.Asset"%>

 

<%

SlingRepository slingRep = sling.getService(SlingRepository.class);

Session session = slingRep.loginAdministrative(null);

QueryBuilder qb ;

Map<String, String> map = new HashMap<String,String>();

map.put("type", "dam.Asset");

map.put("property", "jcr:content/metadata/dc:format");

map.put("property.value", "image/jpeg");

qb=resource.getResourceResolver().adaptTo(QueryBuilder.class);

Query query = qb.createQuery(PredicateGroup.create(map), session);

 

SearchResult sr= query.getResult();

String assetPath=null;

 

 // iterating over the results

  for (Hit hit : sr.getHits()) {

      String path = hit.getPath();

      Resource rs = resourceResolver.getResource(path);

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

     assetPath = asset.getPath();

%>

<img src = "<%= asset.getRendition("cq5dam.thumbnail.140.100.png").getPath()%>" ></img>

<%

}

%>