Expand my Community achievements bar.

SOLVED

AEM 6.5.19 On-Prem Restrict DAM Upload Size (not by mime type)

Avatar

Level 4

We are looking to prevent uploads of very large files, for example we don't want people uploading 1g movies, or 200mb jpegs - or things like that - we probably want to restrict to 50-100mb - and potentially have different rules for different DAM paths, and maybe file types.

AEM Support mentioned there was no way to do this out of the box - I noted it seems to be configurable in their Cloud Service offering - https://experience-aem.blogspot.com/2021/05/aem-cloud-service-configure-file-upload-max-size-per-ass... - support suggested a custom workflow triggered on DAM Upload Asset - to check the file size / (path if required) - and accept or reject (exit) if size is exceeded - before proceeding. 

Has anyone in the community done something similar and would you be willing to share your code?

Support also mentioned this config:  "Day CQ DAM Asset Upload Restriction" - but that doesn't address the file size as far as I can tell.

 

Thank you. 

1 Accepted Solution

Avatar

Correct answer by
Community Advisor

Hi @this-that-the-otter 

 

We have done it for one of the client but can not share more details of it 

 

To limit the size of individual files being uploaded to the AEM DAM, you can create a custom workflow model that includes a process step to validate the size of the asset. Here's a high-level overview of how you can do this:

 

  1. Create a custom workflow model: In AEM, navigate to Tools -> Workflow -> Models. Click on "Create", give your workflow a title and name, and then click on "Done".

  2. Add a process step to the workflow: Drag and drop a "Process Step" from the side panel onto the workflow model. This step will contain the custom code that validates the size of the asset.

  3. Create a custom workflow process step: This is a Java class that implements the WorkflowProcess interface. In the execute method of this class, you can access the asset, check its size, and if it exceeds the limit, terminate the workflow with an error message.

 

Here is a example 

 

@Override
public void execute(WorkItem workItem, WorkflowSession workflowSession, MetaDataMap args) throws WorkflowException {
Asset asset = workflowSession.getSession().getAsset(workItem.getWorkflowData().getPayload().toString());

if (asset != null) {
long size = asset.getOriginal().getSize();
long maxSize = 10485760; // 10MB

if (size > maxSize) {
throw new WorkflowException("File size exceeds the limit of 10MB");
}
}
}

 

  1. Configure the process step in the workflow model: In the workflow model, click on the process step to configure it. In the "Process" field, select your custom workflow process step.

  2. Apply the workflow model to DAM Update Asset workflow: In the DAM Update Asset workflow, replace the existing process step with your new workflow model.

 

 this is a high-level overview and the actual implementation may vary based on your specific requirements and AEM setup.

 

View solution in original post

4 Replies

Avatar

Community Advisor

Hi, 

 

Did you check this? https://www.youtube.com/watch?v=5vKaUwhZMX0&ab_channel=AEMTutorials Sorry, I haven't done this type of requirement myself, but the link you shared is a great starting point if you need to create your own implementation. Perhaps I would remove the UI part and adjust the JS for simplicity, but other than that, it seems like a good approach as well.

 

Hope this helps



Esteban Bustamante

Avatar

Correct answer by
Community Advisor

Hi @this-that-the-otter 

 

We have done it for one of the client but can not share more details of it 

 

To limit the size of individual files being uploaded to the AEM DAM, you can create a custom workflow model that includes a process step to validate the size of the asset. Here's a high-level overview of how you can do this:

 

  1. Create a custom workflow model: In AEM, navigate to Tools -> Workflow -> Models. Click on "Create", give your workflow a title and name, and then click on "Done".

  2. Add a process step to the workflow: Drag and drop a "Process Step" from the side panel onto the workflow model. This step will contain the custom code that validates the size of the asset.

  3. Create a custom workflow process step: This is a Java class that implements the WorkflowProcess interface. In the execute method of this class, you can access the asset, check its size, and if it exceeds the limit, terminate the workflow with an error message.

 

Here is a example 

 

@Override
public void execute(WorkItem workItem, WorkflowSession workflowSession, MetaDataMap args) throws WorkflowException {
Asset asset = workflowSession.getSession().getAsset(workItem.getWorkflowData().getPayload().toString());

if (asset != null) {
long size = asset.getOriginal().getSize();
long maxSize = 10485760; // 10MB

if (size > maxSize) {
throw new WorkflowException("File size exceeds the limit of 10MB");
}
}
}

 

  1. Configure the process step in the workflow model: In the workflow model, click on the process step to configure it. In the "Process" field, select your custom workflow process step.

  2. Apply the workflow model to DAM Update Asset workflow: In the DAM Update Asset workflow, replace the existing process step with your new workflow model.

 

 this is a high-level overview and the actual implementation may vary based on your specific requirements and AEM setup.

 

Avatar

Level 4

Thanks @EstebanBustamante and @Jagadeesh_Prakash. I will pass this along to our developers to see if they are able to incorporate into solution. I appreciate your help!

Avatar

Community Advisor

@this-that-the-otter @, Did you find the suggestions from users helpful? Please let us know if more information is required. For now marking @Jagadeesh_Prakash guidance as possible solution.