Want to restrict multiple uploads of same file in Alfresco 7.0.1

cancel
Showing results for 
Search instead for 
Did you mean: 
shivam1sharma
Member II

Want to restrict multiple uploads of same file in Alfresco 7.0.1

We are using Alfresco 7.0.1, when we upload same file multiple times under document library of any site , it gets uploaded and name got updated with a counter like example-1.png.

We want to restrict the multiple upload of same file with a message like "document already exists".
Is there any simple way to implement this?

Please suggest if any.

3 Replies
sanjaybandhniya
Intermediate

Re: Want to restrict multiple uploads of same file in Alfresco 7.0.1

You can restrict by writing rule or policy.

shivam1sharma
Member II

Re: Want to restrict multiple uploads of same file in Alfresco 7.0.1

I am creating a rule for documentlibrary of the site.

I am executing the script when a document is created or enter,

Script is :

 

function main() {
    // Check if this is a new document creation.
    if (document.isContainer || !document.isDocument) {
        return;
    }

    var folder = document.parent;
    var fileName = document.name;
   
    for (var i = 0; i < folder.children.length; i++) {
   
        if ((folder.children[i].isDocument) && (folder.children[i].name == fileName) && (String(folder.children[i].nodeRef)!=String(document.nodeRef))) {
           
            throw "A file with the"+ fileName + folder.children[i].nodeRef + document.nodeRef +(String(folder.children[i].nodeRef)!=String(document.nodeRef))+" name already exists in this folder. Please choose a different name.";            
        }
    }
}

main();
 
 
 
Please help me with the script.
yamilif
Member II

Re: Want to restrict multiple uploads of same file in Alfresco 7.0.1

Hello, the Rule in this case not prevent the creation of the document with the same name, you most implement a NodeServicePolicies.