I am currently facing an issue with the migration of asset metadata from one aem instance to another aem instance using the App Builder. While i have successfully able to migrate the asset and their metadata from one aem instance to another. I have noticed that the metadata values are being copied to the jcr:content node instead of correct location under jcr:content/metadata. It causing, where not able to see the values of the metadata fields in the asset properties. Also just noticed that dc:title is getting copied to jcr:title under jcr:content.
Below is the piece of code i am using to update metadata. Please let me know how i can correct and solve the issue.
// Update the asset metadata in target AEM targetAemUrl, accessToken2, targetFolderPath, asset, metadata, logger
async function updateAssetMetadata(targetAemUrl, accessToken2, targetFolderPath, assetName, metadata, logger, retryCount = 3) {
const updateUrl = `${targetAemUrl}/api/assets/${targetFolderPath}/${assetName}`;
logger.info(`Updating metadata for asset: ${updateUrl}`);
logger.info(`Metadata: ${JSON.stringify(metadata, null, 2)}`);
const payload = {
class: 'asset',
properties: metadata
};
try {
const response = await fetch(updateUrl, {
method: 'PUT',
headers: {
'Authorization': `Bearer ${accessToken2}`,
'Content-Type': 'application/json'
},
body: JSON.stringify(payload)
});
if (!response.ok) {
if (response.status === 409 && retryCount > 0) {
logger.warn(`Conflict error encountered. Retrying... (${retryCount} retries left)`);
return updateAssetMetadata(targetAemUrl, accessToken2, targetFolderPath, assetName, metadata, logger, retryCount - 1);
}
throw new Error(`Error updating metadata: ${response.statusText}`);
}
const contentType = response.headers.get('content-type');
let responseBody = '';
if (contentType && contentType.includes('application/json')) {
responseBody = await response.json();
logger.info(`Response from updating metadata: ${JSON.stringify(responseBody, null, 2)}`);
} else {
responseBody = await response.text();
logger.info(`Response from updating metadata: ${responseBody}`);
}
logger.info(`Successfully updated metadata for asset: ${assetName}`);
} catch (error) {
logger.error(`Error updating asset metadata: ${error.message}`);
throw error;
}
}
Thanks in advance.