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.
Solved! Go to Solution.
Views
Replies
Total Likes
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:
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".
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.
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");
}
}
}
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.
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.
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
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:
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".
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.
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");
}
}
}
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.
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.
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!
@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.
Views
Likes
Replies