Alfresco: Calculate folder size using Java based WebScript

I was assigned to a training task to write a web script for calculating the size of a folder or a file. But you need to go through all the nodes recursively. If you don't calculate it recursively in folders you won't get accurate folder size.

  • Java Development Kit 1.7 or later
  • Text Editor or IDE (Eclipse/Sublime Text/Atom)
  • Apache Maven 3 or later
  • Web Browser (Chrome/Firefox/Safari)

For this project, I generated Alfresco 5 All-in-One maven project. You really don't want Alfresco  Share module in this project. But I included it because you may need to find a NodeRefId. It would be easier with Share.  Source code of this project is available at GitHub.

Create above files in below locations of your maven project. 
  • size.get.desc.xml - repo-amp/src/main/amp/config/alfresco/extension/templates/webscripts/org/dedunu/alfresco/size.get.desc.xml
  • size.get.html.ftl - repo-amp/src/main/amp/config/alfresco/extension/templates/webscripts/org/dedunu/alfresco/size.get.html.ftl
  • - repo-amp/src/main/java/org/dedunu/alfresco/
  • service-context.xml - repo-amp/src/main/amp/config/alfresco/module/repo-amp/context/service-context.xml
How to test the web script?
Take a terminal. Navigate to project folder. And type below command.

mvn clean install -Prun -Dmaven.test.skip

It may take a while to start the Alfresco Repository and Share server. Wait till it finishes completely. 

Then open a web browser and go to http://localhost:8080/share. Then login. Go to Document library.

Find a folder and click on "View Details". Then copy NodeRef from browser as shown below.

Open a new tab and type below URL. (Replace <NodeRef> with the NodeRef you copied from Alfresco Share interface.)

If you have followed instruction properly, you will get a page like below.

If you have any questions regarding this examples, please comment!!! Enjoy Alfresco!


  1. Sweet!
    There seems to be no way to perform this in pure CMIS, unfortunately... so this is a great tool for Alfresco.
    I wish Alfresco would provide this feature by default within the Share interface, useful before downloading as ZIP or before syncing with CmisSync.
    Repositories tend to get bigger and bigger, and it is not easy to find what is taking a lot of space.
    Next, how about creating a tool like Ubuntu's Baobab, which shows the size of all Sites/folders of the entire repository, as a nice pie chart? :-) That would be very useful to admins who are struggling with disk space.

    1. Yes, I agree with you. I'll try to contribute to Alfresco Community edition and make it work. Thank you for the idea!!!

  2. Nice Post Bro :) Thanks for sharing

  3. Hi,

    Can anyone suggest how to get rid of below FTL error:-

    Message: 06120006 Wrapped Exception (with status template): 06120013 Error during processing of the template 'Expression fileName is undefined on line 11, column 34 in com/trafigura/environment/size.get.html.ftl.'. Please contact your system administrator.

    Exception: freemarker.core.InvalidReferenceException - Expression fileName is undefined on line 11, column 34 in com/trafigura/environment/size.get.html.ftl.

    Thanks in advance..!!

    1. I think you have done a spelling mistake "fileName" in Java file. Please check whether it has correct case as well.

  4. Hi,

    I followed what you have mentioned, but i am getting blank response to FTL file.
    below is the response i am getting from FTL:-

    Check file size

    File Name : fileName

    File Size : size

    Looks like FTL is not capturing the data from controller. Can you please help me with it.

    1. There is a small problem with this webpage rendering. Can you please refer raw FTL file

  5. Hi,

    I too thought to use raw FTL for it. but after using raw FTL , it gives below error:-

    01220003 Wrapped Exception (with status template): 01220017 Error during processing of the template 'Expression fileName is undefined on line 12, column 34 in com/trafigura/environment/size.get.html.ftl.'. Please contact your system administrator.

    Can we try using another format for view like ftl,json? Anyone else got this issue as well?

  6. can you show how to write a unit test for this kind of scenario.

    1. I'm really sorry, I cannot remember anything about alfresco now. Alfresco dev documentation might have information you are looking for.

  7. This post provides clear idea in support of the new visitors of blogging, that in fact how to do running a blog. Check these guys out: How To Learn To Lock Files In 1 Hour.


Post a Comment