cancel
Showing results for 
Search instead for 
Did you mean: 

Limit file upload size 3.4d

asheara
Champ in-the-making
Champ in-the-making
Hi all,

¿Is there any way to limit file size upload in Alfresco 3.4d? I know there's a way to establish user quota, but this is not exactly what we are looking for, we would like to establish different limits to different kind of files (regardless of the connected user) and provide the final user an easy way to modify this limit if necessary.
For example, images files limit to 100kb, css files limit to 200kb…
If it's not possible to separate limit between different kind of files, at least we could establish a common limit to all files.

Any help will be apreciated.
Thanks in advance.
3 REPLIES 3

patil
Champ on-the-rise
Champ on-the-rise
You can do it using the policies and behaviours.
TO know how to use look into

org.alfresco.repo.usage.ContentUsageImpl  check the below method. You can use the similar logic
 public void onUpdateProperties(
            NodeRef nodeRef,
            Map<QName, Serializable> before,
            Map<QName, Serializable> after)
    {
        if (stores.contains(tenantService.getBaseName(nodeRef.getStoreRef()).toString()) && (! alreadyCreated(nodeRef)))
        {
            // Check for change in content size
           
            // TODO use data dictionary to get content property    
            ContentData contentDataBefore = (ContentData)before.get(ContentModel.PROP_CONTENT);
            Long contentSizeBefore = (contentDataBefore == null ? null : contentDataBefore.getSize());
            ContentData contentDataAfter = (ContentData)after.get(ContentModel.PROP_CONTENT);
            Long contentSizeAfter = (contentDataAfter == null ? null : contentDataAfter.getSize());
           
            // Check for change in owner/creator
            String ownerBefore = (String)before.get(ContentModel.PROP_OWNER);
            if ((ownerBefore == null) || (ownerBefore.equals(OwnableService.NO_OWNER)))
            {
                ownerBefore = (String)before.get(ContentModel.PROP_CREATOR);
            }
            String ownerAfter = (String)after.get(ContentModel.PROP_OWNER);
            if ((ownerAfter == null) || (ownerAfter.equals(OwnableService.NO_OWNER)))
            {
                ownerAfter = (String)after.get(ContentModel.PROP_CREATOR);
            }
           
            // check change in size (and possibly owner)
            if (contentSizeBefore == null && contentSizeAfter != null && contentSizeAfter != 0 && ownerAfter != null)
            {
                // new size has been added - note: ownerBefore does not matter since the contentSizeBefore is null
                if (logger.isDebugEnabled()) logger.debug("onUpdateProperties: updateSize (null -> "+contentSizeAfter+"): nodeRef="+nodeRef+", ownerAfter="+ownerAfter);
                incrementUserUsage(ownerAfter, contentSizeAfter, nodeRef);
            }
            else if (contentSizeAfter == null && contentSizeBefore != null && contentSizeBefore != 0 && ownerBefore != null)
            {
                // old size has been removed - note: ownerAfter does not matter since contentSizeAfter is null
                if (logger.isDebugEnabled()) logger.debug("onUpdateProperties: updateSize ("+contentSizeBefore+" -> null): nodeRef="+nodeRef+", ownerBefore="+ownerBefore);
                decrementUserUsage(ownerBefore, contentSizeBefore, nodeRef);
            }
            else if (contentSizeBefore != null && contentSizeAfter != null)
            {
                if (contentSizeBefore.equals(contentSizeAfter) == false)
                {
                    // size has changed (and possibly owner)
                    if (logger.isDebugEnabled()) logger.debug("onUpdateProperties: updateSize ("+contentSizeBefore+" -> "+contentSizeAfter+"): nodeRef="+nodeRef+", ownerBefore="+ownerBefore+", ownerAfter="+ownerAfter);
                   
                    if (contentSizeBefore != 0 && ownerBefore != null)
                    {
                        decrementUserUsage(ownerBefore, contentSizeBefore, nodeRef);
                    }
                    if (contentSizeAfter != 0 && ownerAfter != null)
                    {
                        incrementUserUsage(ownerAfter, contentSizeAfter, nodeRef);
                    }
                }
                else
                {
                    // same size - check change in owner only
                    if (ownerBefore == null && ownerAfter != null && contentSizeAfter != 0 && ownerAfter != null)
                    {
                        // new owner has been added
                        if (logger.isDebugEnabled()) logger.debug("onUpdateProperties: updateOwner (null -> "+ownerAfter+"): nodeRef="+nodeRef+", contentSize="+contentSizeAfter);
                        incrementUserUsage(ownerAfter, contentSizeAfter, nodeRef);
                    }
                    else if (ownerAfter == null && ownerBefore != null && contentSizeBefore != 0)
                    {
                        // old owner has been removed
                        if (logger.isDebugEnabled()) logger.debug("onUpdateProperties: updateOwner ("+ownerBefore+" -> null): nodeRef="+nodeRef+", contentSize="+contentSizeBefore);
                        decrementUserUsage(ownerBefore, contentSizeBefore, nodeRef);
                    }
                    else if (ownerBefore != null && ownerAfter != null && ownerBefore.equals(ownerAfter) == false)
                    {
                        // owner has changed (size has not)
                        if (logger.isDebugEnabled()) logger.debug("onUpdateProperties: updateOwner ("+ownerBefore+" -> "+ownerAfter+"): nodeRef="+nodeRef+", contentSize="+contentSizeBefore);
                       
                        if (contentSizeBefore != 0)
                        {
                            decrementUserUsage(ownerBefore, contentSizeBefore, nodeRef);
                        }
                        if (contentSizeAfter != 0)
                        {
                            incrementUserUsage(ownerAfter, contentSizeAfter, nodeRef);
                        }
                    }
                }
            }
        }
    }


Thanks,
Patil
CignexDatamatics
Bangalore

asheara
Champ in-the-making
Champ in-the-making
Hi,

We can't do extra development for this solution. We have been looking through Alfresco wiki and we didn't find anything like this, if there's a way to establish this file upload size limit by simple configuration or by alfresco admin window, ¿could you please provide any documentation about this?
We're looking for documentation about this, but we didn't find anythig, so we think it's not possible to do what we want to do in an easy way.

Thanks!

patil
Champ on-the-rise
Champ on-the-rise
Nope, out of the box this feature is not available.
You have to do the custom devlopment.

Thanks,
Patil
Cignex Datamatics
Bangalore