Your achievements

Level 1

0% to

Level 2

Tip /
Sign in

Sign in to Community

to gain points, level up, and earn exciting badges like the new
Bedrock Mission!

Learn more

View all

Sign in to view all badges

SOLVED

Rename asset file names on upload

Avatar

Community Advisor

Hi All,

 

Is there a way to overlay/interject the CreateAssetServlet and make sure the filename contains valid (allowed characters)? Or even the js calling the servlet to pass a desired filename?

 

I see here that there are valid characters that are allowed in classic ui. However when I upload using a space or other characters, the filename still has those (AEM 6.5.10 On premise)

I see http://experience-aem.blogspot.com/2020/08/aem-6550-modify-filename-on-upload-before-executing-dam-u... where a Filter is used but still looking to see if a simple interjection can be used instead of using a filter that seems to be doing much.

 

Another option I have is use a custom workflow (not impacting dam update wf) and add a process step to rename the file name that is suitable.

 

1 Accepted Solution

Avatar

Correct answer by
Community Advisor

Hi @Shubham_borole ,

 

If you want to rename the file name before uploading to DAM. FileUpload.js is the best way to go,

To achieve this, we would need to overlay the fileupload.js in : /libs/dam/gui/coral/components/commons/fileupload/clientlibs/fileupload/js/fileupload.js

 

In that file you will notice, there are multiple operations happening on the asset name before uploading.

Just create a function to replace certain chars and then call it within any such operations.

View solution in original post

5 Replies

Avatar

Community Advisor

@Shubham_borole ,

 

Filter is good way to proceed in your use case because if you want to rename the file before you save it is an efficient way to rename the asset file than renaming asset later.

if you do not have any other process such as assigning metadata or any other activities then you can consider implementing sling resource change listener.

 

 

Avatar

Community Advisor

@Aruna_surukunta_ - I agree, hence I am trying to find a way where I could feed a desired filename so that even a filter invocation is not required. The filter will be called for every request. Although we will have proper checks but still it will be called and checked in all instances.

 

I was/am just a bit hesitant to touch javax.servlet.http.Part, it seems to be dealing with io for all request. Not seen it referred widely (any thoughts?)

 

Will try to weigh pro and cons. Thanks a lot.

Will hang on for more thoughts on this as well.

Avatar

Correct answer by
Community Advisor

Hi @Shubham_borole ,

 

If you want to rename the file name before uploading to DAM. FileUpload.js is the best way to go,

To achieve this, we would need to overlay the fileupload.js in : /libs/dam/gui/coral/components/commons/fileupload/clientlibs/fileupload/js/fileupload.js

 

In that file you will notice, there are multiple operations happening on the asset name before uploading.

Just create a function to replace certain chars and then call it within any such operations.

Avatar

Community Advisor

Thanks @Anmol_Bhardwaj Is "/libs/cq/ui/widgets/source/widgets/UploadDialog.js" an equivalent for classic ui?

I tried making a simple text change on that file but the upload dialog does not seem to update based on that.

When search for the contents of UploadDialog.js I can see them under "http://localhost:4502/libs/cq/ui/widgets.js" however the manual changes are not reflected even if I make the change on the overlay file or the libs file directly.

Avatar

Community Advisor

Update: Looks like this is the one that is used - /libs/cq/ui/widgets/source/widgets/html5/UploadDialog.js, will overlay that to /apps/cq/ui/widgets/source/widgets/html5/UploadDialog.js and try

 

Thanks