내 커뮤니티 업적 표시줄을 확대합니다.

Submissions are now open for the 2026 Adobe Experience Maker Awards.

Mark Solution

활동이 없어 이 대화는 잠겼습니다. 새 게시물을 작성해 주세요.

해결됨

Touch UI Validate Asset file names on Upload

Avatar

Level 3

Hi All,

 

I want to validate asset file names at the time of upload asset in dam.

When uploading new asset in DAM can there be a validation script which will only allow the supported (by AEM and Dynamic Media) characters within the file name. file name only allow these  a-z A-Z - _ 0-9.

 

I have try one solution but that is not working.

http://experience-aem.blogspot.com/2018/11/aem-6420-touch-ui-validate-asset-file-names-on-upload.htm...

 

Please could anyone suggest how can i do that.

 

 

Thanks.

1 채택된 해결책 개

Avatar

정확한 답변 작성자:
Level 10
6 답변 개

Avatar

Level 10

Hello @user00181 - 

 

You can write/customize the below script further as per your use-case : 

 

package com.yourpackage;

import org.apache.commons.lang3.StringUtils;
import org.apache.sling.api.SlingHttpServletRequest;
import org.apache.sling.api.SlingHttpServletResponse;
import org.apache.sling.api.servlets.SlingAllMethodsServlet;

import javax.servlet.Servlet;
import javax.servlet.ServletException;
import java.io.IOException;
import java.util.regex.Pattern;

public class CustomAssetUploadServlet extends SlingAllMethodsServlet implements Servlet {

    private static final Pattern FILENAME_PATTERN = Pattern.compile("^[a-zA-Z0-9-_]+$");

    @Override
    protected void doPost(SlingHttpServletRequest request, SlingHttpServletResponse response) throws ServletException, IOException {
        // Get the uploaded file name
        String fileName = request.getRequestPathInfo().getSuffix();

        // Validate the file name against supported characters
        if (!isValidFileName(fileName)) {
            response.sendError(SlingHttpServletResponse.SC_BAD_REQUEST, "Invalid file name. File names can only contain a-z, A-Z, 0-9, hyphen (-), and underscore (_).");
            return;
        }

        // Continue with the default asset upload logic
        super.doPost(request, response);
    }

    private boolean isValidFileName(String fileName) {
        return StringUtils.isNotBlank(fileName) && FILENAME_PATTERN.matcher(fileName).matches();
    }
}

 

Avatar

Level 3

How I can call this class at the time of assert upload in Dam.

Avatar

Level 10

@user00181  - 

 

Develop a custom workflow process in AEM that intercepts the asset upload operation and performs the file name validation.

 

  • Implement a custom Java class that represents the workflow process step responsible for file name validation. This class should extend the AbstractWorkflowProcess or AbstractAssetWorkflowProcess class provided by AEM.

Avatar

정확한 답변 작성자:
Level 10

Avatar

Community Advisor

Avatar

Employee Advisor

Hi,

 

o validate asset file names during upload in AEM DAM, develop a custom OSGi bundle implementing AssetUploadNameValidator interface. Override the validate method to check for unsupported characters. Register the bundle as an OSGi service and configure it in AEM's OSGi settings.