Issue facing in AEM Workflow Custom Process Step | Community
Skip to main content
New Participant
April 23, 2025
Solved

Issue facing in AEM Workflow Custom Process Step

  • April 23, 2025
  • 2 replies
  • 550 views

We have written a custom workflow process that’s supposed to resize an image and create a new rendition whenever an asset is uploaded under /content/dam/projects. The code executes without throwing any errors, but the resized image isn't getting created, and I don’t see any new rendition added. Here's the snippet:

@9944223 public void execute(WorkItem workItem, Session session, MetaDataMap metaData) { try { String path = workItem.getWorkflowData().getPayload().toString(); ResourceResolver resolver = ...; // Get from service user or workflow session Resource resource = resolver.getResource(path); if (resource != null && resource.adaptTo(Asset.class) != null) { Asset asset = resource.adaptTo(Asset.class); Rendition original = asset.getOriginal(); try (InputStream input = original.getStream()) { Layer layer = new Layer(input); layer.resize(800, 600); // Resize to 800x600 asset.addRendition("custom-resized", layer.getInputStream(), "image/jpeg"); } } } catch (Exception e) { e.printStackTrace(); } }

I am not seeing any errors, but the resized rendition is not being saved. What could be the issue here?

 
Best answer by SantoshSai

Hi @navyavo,

I’m not entirely sure, but a few things might be going wrong here:

Maybe the ResourceResolver you're using doesn’t have the necessary permissions to write to the DAM. If it’s not coming from a properly configured service user, the rendition might never get saved—even if no error is thrown.

You might want to check if the resolver is obtained like this:

resourceResolverFactory.getServiceResourceResolver(
  Collections.singletonMap(ResourceResolverFactory.SUBSERVICE, "your-subservice-name")
)

And make sure the service user has write access to /content/dam.

 

It’s possible that Layer isn't resizing the image correctly. This can happen if the input stream is invalid, or if the image format isn’t fully supported.

Maybe add a quick log like:

log.info("Original dimensions: {}x{}", layer.getWidth(), layer.getHeight());

Just to confirm the resize is actually happening.

 

Hope that helps!

2 replies

SantoshSai
SantoshSaiAccepted solution
New Participant
April 23, 2025

Hi @navyavo,

I’m not entirely sure, but a few things might be going wrong here:

Maybe the ResourceResolver you're using doesn’t have the necessary permissions to write to the DAM. If it’s not coming from a properly configured service user, the rendition might never get saved—even if no error is thrown.

You might want to check if the resolver is obtained like this:

resourceResolverFactory.getServiceResourceResolver(
  Collections.singletonMap(ResourceResolverFactory.SUBSERVICE, "your-subservice-name")
)

And make sure the service user has write access to /content/dam.

 

It’s possible that Layer isn't resizing the image correctly. This can happen if the input stream is invalid, or if the image format isn’t fully supported.

Maybe add a quick log like:

log.info("Original dimensions: {}x{}", layer.getWidth(), layer.getHeight());

Just to confirm the resize is actually happening.

 

Hope that helps!

Santosh Sai
NavyaVoAuthor
New Participant
April 24, 2025

Thank you!
I actually tried adding resolver.commit() after asset.addRendition(), but unfortunately that wasn’t the issue in this case.

The root cause turned out to be that theResourceResolver I was using didn’t have sufficient permissions to write to /content/dam. Even with the commit call, the changes weren’t getting saved because the resolver itself wasn’t authorized to make those modifications.

Once I switched to a properly mapped service user with the right permissions, everything worked as expected - even without manually calling commit() .

New Participant
April 23, 2025

Hi @navyavo ,

 

I think the logic that you have written is good, you just need to add below code after asset.addRendition() line to save all the changes.

resolver.commit();

It saves all the unsaved changes you’ve made using that Resource Resolver to the JCR repository (AEM’s content database). 

Let me know if it works or you need more help.

Thanks.