Expand my Community achievements bar.

July 31st AEM Gems Webinar: Elevate your AEM development to master the integration of private GitHub repositories within AEM Cloud Manager.

AEM Cloud Service - Dynamic Media folder path length validation, prevent deep nesting | AEM Community Blog Seeding




AEM Cloud Service - Dynamic Media folder path length validation, prevent deep nesting by Sreekanth Choudry Nalabotu


AEM Cloud Version : 2021.2.4944.20210221T230729Z-210225 (Feb 21, 2021)

When the Scene7 sync path (including account name) is more than 255 chars, asset upload to AEM works fine, however sync to Scene7 fails with error in s7 job console Failed to insert to DB. This post is on providing folder path validation (240 chars) so users do not upload assets in a deep nested structure and corrupt the repo with DM sync failures...

1) Create a filter apps.experienceaem.assets.core.filters.FolderNestingCheck, to provide server side validation of folder path lengths...

package apps.experienceaem.assets.core.filters;

import org.apache.sling.api.SlingHttpServletRequest;
import org.apache.sling.api.SlingHttpServletResponse;
import org.osgi.framework.Constants;
import org.osgi.service.component.annotations.Component;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import javax.servlet.*;
import java.io.IOException;

service = Filter.class,
immediate = true,
name = "Experience AEM folder nesting check",
property = {
Constants.SERVICE_RANKING + ":Integer=-99",
public class FolderNestingCheck implements Filter {
private static Logger log = LoggerFactory.getLogger(FolderNestingCheck.class);

private static int S7_FOLDER_LENGTH_MAX = 240;
private static String CONTENT_DAM_PATH = "/content/dam";
private static String INITIATE_UPLOAD_JSON = ".initiateUpload.json";
private static String CREATE_ASSET_HTML = ".createasset.html";

public void init(FilterConfig filterConfig) throws ServletException {

public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
throws IOException, ServletException {
SlingHttpServletRequest slingRequest = (SlingHttpServletRequest)request;
SlingHttpServletResponse slingResponse = (SlingHttpServletResponse)response;

String uri = slingRequest.getRequestURI();

if(!uri.endsWith(INITIATE_UPLOAD_JSON) && !uri.endsWith(CREATE_ASSET_HTML)){
chain.doFilter(request, response);

String folderPath = uri.substring(uri.indexOf(CONTENT_DAM_PATH) + CONTENT_DAM_PATH.length());

folderPath = folderPath.substring(0, folderPath.lastIndexOf(INITIATE_UPLOAD_JSON));
}else if(folderPath.endsWith(CREATE_ASSET_HTML)){
folderPath = folderPath.substring(0, folderPath.lastIndexOf(CREATE_ASSET_HTML));

if(folderPath.length() > S7_FOLDER_LENGTH_MAX){
log.info("Uploading to deep nested folders not allowed : " + uri);
slingResponse.sendError(SlingHttpServletResponse.SC_FORBIDDEN, "Uploading to deep nested folders not allowed: " + uri);

chain.doFilter(request, response);
}catch(Exception e){
log.error("Error checking folder nesting", e);

public void destroy() {
2) For showing the validation alert in browser, create a clientlib /apps/eaem-cs-no-deep-nesting/clientlibs/no-deep-nesting with categories dam.gui.coral.fileupload

3) Add JS logic for validation in /apps/eaem-cs-no-deep-nesting/clientlibs/no-deep-nesting/deep-nesting-upload.js

Read Full Blog

AEM Cloud Service - Dynamic Media folder path length validation, prevent deep nesting


Please use this thread to ask the related questions.

Kautuk Sahni

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

0 Replies