When I upload an image on AEM it takes few seconds before it gets processed. However if its not fully processed and I try to publish it it fails. Is there a way to programatically know if a given image is processed or not? (Using Assets. / Replicate or some other API)?
Solved! Go to Solution.
Views
Replies
Total Likes
Hi @spidey1405,
Assuming you are using OOTB DAM Update Asset workflow then you can utilize information that is generated by DAM Update Asset Workflow Completed step. This step is also responsible to set dam:assetState property value to processed. As part of this step DAM_UPDATE_ASSET_WORKFLOW_COMPLETED event is send when DAM Update Asset workflow is completed. Having this knowledge, you can simply create event handler that will be listening on above topic. Here is very basic example:
package com.mysite.core.handler; import com.day.cq.dam.api.DamEvent; import org.osgi.service.component.annotations.Component; import org.osgi.service.event.Event; import org.osgi.service.event.EventConstants; import org.osgi.service.event.EventHandler; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @Component( immediate = true, service = EventHandler.class, property = EventConstants.EVENT_TOPIC + "=" + DamEvent.EVENT_TOPIC) public class DAMEventHandler implements EventHandler { private static final Logger LOG = LoggerFactory.getLogger(DAMEventHandler.class); @Override public void handleEvent(Event event) { DamEvent damEvent = DamEvent.fromEvent(event); if (DamEvent.Type.DAM_UPDATE_ASSET_WORKFLOW_COMPLETED.equals(damEvent.getType())) { LOG.info("Processed asset path: " + damEvent.getAssetPath()); // place for your code } } }
and one more, but more complex:
Above solution will prevent you to check dam:assetState property periodically (for given asset) and generate unnecessary load on AEM instance.
Hi @spidey1405,
Assuming you are using OOTB DAM Update Asset workflow then you can utilize information that is generated by DAM Update Asset Workflow Completed step. This step is also responsible to set dam:assetState property value to processed. As part of this step DAM_UPDATE_ASSET_WORKFLOW_COMPLETED event is send when DAM Update Asset workflow is completed. Having this knowledge, you can simply create event handler that will be listening on above topic. Here is very basic example:
package com.mysite.core.handler; import com.day.cq.dam.api.DamEvent; import org.osgi.service.component.annotations.Component; import org.osgi.service.event.Event; import org.osgi.service.event.EventConstants; import org.osgi.service.event.EventHandler; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @Component( immediate = true, service = EventHandler.class, property = EventConstants.EVENT_TOPIC + "=" + DamEvent.EVENT_TOPIC) public class DAMEventHandler implements EventHandler { private static final Logger LOG = LoggerFactory.getLogger(DAMEventHandler.class); @Override public void handleEvent(Event event) { DamEvent damEvent = DamEvent.fromEvent(event); if (DamEvent.Type.DAM_UPDATE_ASSET_WORKFLOW_COMPLETED.equals(damEvent.getType())) { LOG.info("Processed asset path: " + damEvent.getAssetPath()); // place for your code } } }
and one more, but more complex:
Above solution will prevent you to check dam:assetState property periodically (for given asset) and generate unnecessary load on AEM instance.
Whenever DAM Update Asset Workflow finishes with Asset processing, dam:assetState property is set as processed. Please see the screen shot below.
You can check this property before replicating the Asset programmatically.
Hey @krati_garg so does that mean when the processing is going on it would not show processed? What would be the value at that time?
Hi @spidey1405 ,
You can check for the property "dam:assetState" of asset inside jcr:content. For Processed asset it should appear as "processed" for unprocessed it should appear as "unProcessed".
Hey Tarun what about processing? Basically when it is in processing does it show processed or unprocessed?
Hi @spidey1405 ,
It appears as "processing" as far as I remember, however I will have to double check it by reproducing the scenario.
Views
Likes
Replies
Views
Likes
Replies
Views
Likes
Replies