File name validation in AEM forms | Community
Skip to main content
manikanthar1295
Level 5
April 12, 2022
Solved

File name validation in AEM forms

  • April 12, 2022
  • 2 replies
  • 1952 views

Hi Team,

 

I have simple AEM  form in that  there is file  attachment field.

Now the requirement is file name should not contain any special characters if it contains special character i have to show custom error message like "Attached File  name contains special  character"

 if any one did like this please share the knowledge

 

 

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Best answer by Pulkit_Jain_

@manikanthar1295 

That's the purpose of implementing this API i.e to get the file attachment component attributes. In the case at hand, you can set an alert/warning for the user to re-upload the file with the expected name.

Any further implementation (resetting/deleting the value of the component) has to be taken care of using javascript.

2 replies

Pulkit_Jain_
Adobe Employee
Adobe Employee
April 13, 2022

@manikanthar1295 

OOTB, the file attachment component does not support attaching files with a filename starting with characters (.), containing characters \ / : * ? " < > | ; % $.

Otherwise, you can configure a check with getFileAttachmentsInfo as below:

guideBridge.getFileAttachmentsInfo({
    success: function (list) {
 //some specific file names that are supported     
            } else 
            if (fileName.match(/["add the special character here"]/)) {
              alert("File name cannot contain a special character.");
            }
});

Hope this helps!

 

[0] - 

https://helpx.adobe.com/experience-manager/6-5/forms/javascript-api/GuideBridge.html#getFileAttachmentsInfo__anchor

 

manikanthar1295
Level 5
April 18, 2022

@pulkit_jain_ ,

guideBridge.getFileAttachmentsInfo({
    success: function (list) {
 //some specific file names that are supported     
            } else 
            if (fileName.match(/["add the special character here"]/)) {
              alert("File name cannot contain a special character.");
            }
});

 

Above code only give the file info like name and path of the file but we are not able to avoid the upload how we can achive the uploading file

 

Pulkit_Jain_
Adobe Employee
Pulkit_Jain_Adobe EmployeeAccepted solution
Adobe Employee
April 18, 2022

@manikanthar1295 

That's the purpose of implementing this API i.e to get the file attachment component attributes. In the case at hand, you can set an alert/warning for the user to re-upload the file with the expected name.

Any further implementation (resetting/deleting the value of the component) has to be taken care of using javascript.

Mayank_Gandhi
Adobe Employee
Adobe Employee
April 14, 2022

@manikanthar1295 This is certainly possible, using 

getFileAttachmentsInfo

You will have to implement logic to delete the uploaded file in case of regex failure.  

manikanthar1295
Level 5
April 18, 2022

@mayank_gandhi  @pulkit_jain_ 

 

I am able to get the file info like file name and path of the file based on regex expression i can test the file name with regex now if it contain special character how i can delete that special character file  which object i need to use to delete if you have any example please share here.

 

 

@mayank_gandhi   need your input here

Mayank_Gandhi
Adobe Employee
Adobe Employee
April 18, 2022

@manikanthar1295 If it's client-side then you should rather prompt the user with a warning and ask him to reupload the file with the correct pattern.