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
Solved! Go to Solution.
Views
Replies
Total Likes
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.
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] -
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
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.
@manikanthar1295 This is certainly possible, using
getFileAttachmentsInfo
You will have to implement logic to delete the uploaded file in case of regex failure.
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
@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.
guideBridge.getFileAttachmentsInfo will give path and name of file but we are able to upload the file into tmp location how we can make based on regex
if file name fails in regex match we need to avoid uploading the attachment how we can achive this if you have any code please share with us
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."); } });
@manikanthar1295 here is a quick workaround, use the click method with the id (x) of the delete icon that comes with the attachment to remove the file in the failure block.
document.getElementById("myCheck").click();
Views
Replies
Total Likes
Views
Likes
Replies