Expand my Community achievements bar.

AEM 6550 - Find the Asset Reference in S3 Data Store | AEM Community Blog Seeding

Avatar

Administrator

BlogImage.jpg

AEM 6550 - Find the Asset Reference in S3 Data Store by Sreekanth Choudry Nalabotu

Abstract

For debugging purposes if you need the asset S3 unique id for locating it in Cloud Data Store...

1) Install the Package

2) Pass the asset path to script eg. http://localhost:4502/apps/eaem-get-s3-reference/content.html/content/dam/sreek-local/sreek_KBYG_Reservations_Video_V10.mov

3) Using AWS Tools (Cmdlets) for Windows PowerShell locate the blob (stored in flat structure....)

Set-AWSCredential -AccessKey MY_S3_ACCESS_KEY -SecretKey MY_LONG_S3_SECRET_KEY -StoreAs experience-aem-profile
Set-AWSCredential -ProfileName experience-aem-profile
Get-S3Bucket -BucketName experience-aem-bucket
Get-S3Object -BucketName experience-aem-bucket -Key c086d8a58a2787f99ef6dffb6fab8c1f2f501604bac16c1eff4c767cd77294fd


4) The script in /apps/eaem-get-s3-reference/eaem-get-s3-reference.jsp to get the S3 reference...

<%@ page import="org.apache.commons.lang3.StringUtils" %>
<%@ page import="com.day.cq.dam.commons.util.DamUtil" %>
<%@ page import="org.apache.sling.api.resource.Resource" %>
<%@ page import="com.day.cq.commons.jcr.JcrConstants" %>
<%@ page import="javax.jcr.Node" %>
<%@ page import="javax.jcr.Property" %>
<%@ page import="org.apache.jackrabbit.api.ReferenceBinary" %>
<%@ page import="org.apache.sling.api.resource.ResourceResolver" %>
<%@ page import="org.apache.sling.api.SlingHttpServletRequest" %>
<%@ page import="com.day.cq.dam.api.Asset" %>

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

<%

SlingHttpServletRequest eaemSlingRequest = slingRequest;
String assetPath = eaemSlingRequest.getRequestPathInfo().getSuffix();

if(StringUtils.isEmpty(assetPath)){
response.getWriter().print("No suffix provided, sample usage - /apps/eaem-get-s3-reference/content.html/content/eaem/big-video.mov");
return;
}

ResourceResolver eaemResolver = eaemSlingRequest.getResourceResolver();
Resource s3Resource = eaemResolver.getResource(assetPath);

String assetIdSha246 = getS3AssetIdFromReference(s3Resource);

response.getWriter().print("Asset : " + assetPath + "

");
response.getWriter().print("S3 Reference : " + assetIdSha246);
%>

<%!
public static String getS3AssetIdFromReference(final Resource assetResource) throws Exception {
String s3AssetId = StringUtils.EMPTY;

if( (assetResource == null) || !DamUtil.isAsset(assetResource)){
return s3AssetId;
}

Resource original = assetResource.getChild(JcrConstants.JCR_CONTENT + "/renditions/original/jcr:content");

if(original == null) {
return s3AssetId;
}

Node orgNode = original.adaptTo(Node.class);

if(!orgNode.hasProperty("jcr:data")){
return s3AssetId;
}

Property prop = orgNode.getProperty("jcr:data");

ReferenceBinary value = (ReferenceBinary)prop.getBinary();

s3AssetId = value.getReference();

if(StringUtils.isEmpty(s3AssetId) || !s3AssetId.contains(":")){
return s3AssetId;
}

s3AssetId = s3AssetId.substring(0, s3AssetId.lastIndexOf(":"));

s3AssetId = s3AssetId.substring(0, 4) + "-" + s3AssetId.substring(4);

return s3AssetId;
}
%>

Read Full Blog

AEM 6550 - Find the Asset Reference in S3 Data Store

Q&A

Please use this thread to ask the related questions.



Kautuk Sahni
Topics

Topics help categorize Community content and increase your ability to discover relevant content.

0 Replies