Expand my Community achievements bar.

Learn about Edge Delivery Services in upcoming GEM session
SOLVED

How to restrict special characters for asset filenames in AEM DAM

Avatar

Community Advisor

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.

1 Accepted Solution

Avatar

Correct answer by
Community Advisor

Hi @Aruna_surukunta_,

 

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.

View solution in original post

8 Replies

Avatar

Employee Advisor

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... 

 

Avatar

Community Advisor

@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

 

Avatar

Correct answer by
Community Advisor

Hi @Aruna_surukunta_,

 

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.

Avatar

Community Advisor

@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.

 

Avatar

Community Advisor

Hi @Aruna_surukunta_ ,

 

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-valida...

Avatar

Community Advisor
@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.

Avatar

Community Advisor

@Aruna_surukunta_,

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.AssetUploadRestrict...

 

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.

Screenshot 2021-01-25 at 09.45.58.png