How to restrict special characters for asset filenames in AEM DAM | Community
Skip to main content
Anny0505
Community Advisor
Community Advisor
January 24, 2021
Solved

How to restrict special characters for asset filenames in AEM DAM

  • January 24, 2021
  • 4 replies
  • 6971 views

Hi All,

If anyone implement or have idea on restricting special chanracters for filenames for assets Please let me know. Business users sometimes uploading files with special characters with asset files using touch UI and they are creating some issues. I wanted to to restrict such kind of situations.

 

I did some analysis on fileupload.js to restrict some characters but for some reason it is not working as I expected.

 

If any thoughts or suggestions on this implementation really help me.

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 Kiran_Vedantam

Hi @anny0505,

 

As you already know that the assets are uploaded in /content/dam. Hence, we can use the Event handling approach.

 

  1. Write an event listener/workflow/schedulers to listen to the event [node added/ removed etc.] of uploading the assets at the particular content path
  2. Fetch the file name and check for special characters
  3. Replace them with the characters which are generic, then save the node

You can refer to my post on different annotations here.

 

Hope this helps.

 

Thanks,

Kiran Vedantam.

4 replies

Kunal_Gaba_
January 25, 2021

You can write a request filter to validate the asset before it gets uploaded in AEM. 

 

You can find a sample of that filter here - http://experience-aem.blogspot.com/2018/11/aem-6420-file-decode-filter-virus-scan-to-decode-uploaded-files-for-create-asset-servlet.html 

 

Anny0505
Community Advisor
Anny0505Community AdvisorAuthor
Community Advisor
January 25, 2021

@kunal_gaba_, Thank you.

 

I believe this is really good and helpful information.

Thanks a lot. I am going to try this and update you.

 

 Sorry, If it is a dumb question,  let's say I have implemented a filter to check the filename special chars and It is successfully removed characters from the filename. after that how to redirect to create asset servelet. Do I need to take any extra things to take care?

 

Thanks,

Aruna

 

Kiran_Vedantam
Community Advisor
Kiran_VedantamCommunity AdvisorAccepted solution
Community Advisor
January 25, 2021

Hi @anny0505,

 

As you already know that the assets are uploaded in /content/dam. Hence, we can use the Event handling approach.

 

  1. Write an event listener/workflow/schedulers to listen to the event [node added/ removed etc.] of uploading the assets at the particular content path
  2. Fetch the file name and check for special characters
  3. Replace them with the characters which are generic, then save the node

You can refer to my post on different annotations here.

 

Hope this helps.

 

Thanks,

Kiran Vedantam.

Anny0505
Community Advisor
Anny0505Community AdvisorAuthor
Community Advisor
January 25, 2021

@kiran_vedantam

 

Thank you very much for your suggestion. I really appreciate it. 

 

When I upload assets into AEM DAM I am doing few extra operations such as running Graphics magics commands and writing the asset to another static server.

Because of these 2 operations, I am a little worried about the event listeners approach.

Otherwise, it is a really good suggestion and I am sure it is going to fix my issue if I don't have extra operations on the asset.

 

I also tried with Upload file JS but it is not helpful in case if I have china characters in filenames.

If you have any other solutions/suggestions please let me know.

 

Thank you once again.

 

ChitraMadan
Community Advisor
Community Advisor
January 25, 2021

Hi @anny0505 ,

 

You can also overlay the js file which is responsible for doing the validation and add your special characters in the list.

Please refer to this - https://experienceleaguecommunities.adobe.com/t5/adobe-experience-manager/extending-file-name-validation-in-aem-assets/qaq-p/298210

Anny0505
Community Advisor
Anny0505Community AdvisorAuthor
Community Advisor
January 25, 2021
@chitramadan, Thank you for the answer. I wanted to restrict spcial characters which are not a-z,A-z and 0-9. I did try this JS for some extent it is working. still i need to restrict other characters too. like CHinesee chars from the filenames. If you have any exposure to it please advise me.
BrianKasingli
Community Advisor and Adobe Champion
Community Advisor and Adobe Champion
January 25, 2021

@anny0505,

You can configure the Day CQ DAM Asset Upload Restriction service from the OSGI console http://localhost:4502/system/console/configMgr/com.day.cq.dam.core.impl.mimeType.AssetUploadRestrictionHelper

 

To restrict users to upload files of certain MIME types only, unselect the allow all MIME option and specify allowed MIME types in the Allowed Asset MIMEs (regex) fields using regular expressions.

 

 

Anny0505
Community Advisor
Anny0505Community AdvisorAuthor
Community Advisor
January 25, 2021
@briankasingli, Thank you for providing the info. It is useful.