Fetching smart crop and its properties using Asset Http Api | Community
Skip to main content
Level 4
December 16, 2024
Solved

Fetching smart crop and its properties using Asset Http Api

  • December 16, 2024
  • 2 replies
  • 824 views

Hi,

 

Currently i am trying to migrate assets and its metadata with smart crop images from one aem cloud instance to another aem cloud instance. I can able to fetch the asset and its metadata from the source aem folder. would like to know is there any api we can use to fetch the smart crops also? When i hit the /api/assets/wknd/investors/asset.jpg/renditions.json -> i am getting only the renditions not the smart crops image details.

 

/api/assets/wknd/investors/asset.jpg.json/jcr:content/metadata.json -> giving the metadata properties. I could see that

hasLocalCrops: true

Anyone has any idea how to retrieve the smart crop images. I am using Aio app builder in this migration process.

 

 

 

Thanks,

Bhavani Bharanidharan

 

 

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 BhavaniBharani

Below api and the function will give the smart crop of the assets in the json format. 

async function fetchSmartCrop(aemUrl, accessToken, folderPath, assetName) {
console.log("Fetch Asset metadata of:", assetName);
const smartCropUrl = `${aemUrl}/content/dam/${folderPath}/${assetName}/jcr:content.3.json`;
console.log(`smart crop: ${smartCropUrl}`);
try {
const response = await fetch(smartCropUrl, {
method: 'GET',
headers: {
'Authorization': `Bearer ${accessToken}`
}
});
if (!response.ok) {
throw new Error(`Error fetching metadata: ${response.statusText}`);
}
const smartCropProperties = await response.json();
console.log(`Smart crop: ${JSON.stringify(smartCropProperties, null, 2)}`);
return smartCropProperties;
} catch (error) {
console.log(`Error fetching asset smartcrop: ${error.message}`);
throw error;
}
}

2 replies

anupampat
Community Advisor
Community Advisor
December 16, 2024

Hi @bhavanibharani ,

 

Since you are moving the assets from one Cloud instance to another, the Assets will still be processed on the new AEM instance, since smart crop is a configuration, doesn't it make sense to have it configure it on the new instance and let it run when assets are uploaded as part of the Post Processor ?

 

I can imagine you would want to save resource by including the smart crops via API as well but it would make more sense to let the new system do the processing.

 

Regards,
Anupam Patra

BhavaniBharaniAuthorAccepted solution
Level 4
December 26, 2024

Below api and the function will give the smart crop of the assets in the json format. 

async function fetchSmartCrop(aemUrl, accessToken, folderPath, assetName) {
console.log("Fetch Asset metadata of:", assetName);
const smartCropUrl = `${aemUrl}/content/dam/${folderPath}/${assetName}/jcr:content.3.json`;
console.log(`smart crop: ${smartCropUrl}`);
try {
const response = await fetch(smartCropUrl, {
method: 'GET',
headers: {
'Authorization': `Bearer ${accessToken}`
}
});
if (!response.ok) {
throw new Error(`Error fetching metadata: ${response.statusText}`);
}
const smartCropProperties = await response.json();
console.log(`Smart crop: ${JSON.stringify(smartCropProperties, null, 2)}`);
return smartCropProperties;
} catch (error) {
console.log(`Error fetching asset smartcrop: ${error.message}`);
throw error;
}
}