Javascript check if object is a file or a folder

Hi! Is there a possibility to check if the object to be uploaded (for example in the Document item's File tab/upload field) is a file or a folder? We would like to prevent folders from ever being uploaded in Files (like a javascript check when you drag&drop a file/folder), and so far we can't see an attribute in database or anywhere else which does the check. Thanks.

  • Hi Keipidesu

    I have done this with server side code to prevent uploading specific file types in Document Files tab. May be you can see whether it is useful in your case

    Method Type : Server Side (C#)

    Hooks : Item Type's Server Event (Here Document Files Item Type)

    Method Code:

    Innovator inn = this.getInnovator();
    Item file = this.getRelatedItem();
    string filetype = file.getProperty("file_type");
    // IDs of File Types : 7z Archive, GZ Archive, MHTML Web Archive and ZIP Archive
    if (filetype == "37F8C7E3B74F418FBFEE82A47D4FB58F" || filetype == "FBFF07AC45C04698981A40C292AA75F5" || filetype == "66D94C1CE5B848FFAD8B6B1C38E3035B" || filetype == "238E3419BA7648AC9F37313E84474735")
    return inn.newError("Uploading Archive File(s) and Folders is not allowed. Please remove and save the item.");
    return this;

    Note: You can block other file types also. To get the IDs of other file types go to Administration --> File Handling --> File Types (Right click and select properties to copy the ID).

    If I'm able to get this done in JavaScript, Will keep you updated here.

    Thank You

    Gopikrishnan R

  • Hi Gopikrishnan
    Thank you sharing the server side of the code! However, what we are looking for is not handling specific file types/file extensions, but rather if the object passed is a folder (in itself) or a file. Our initial javascript program also included handling file types, but when given a for example, a folder name called "folder.docx", even though its entity is a folder, Aras still registers it as a Word document file, same as with ~.xlsx, etc.. or even folder without extension names. We have also found later on that the Vault Server unfortunately treats and registers them as files.

    I know this is an annoying test case. But we are also looking into that angle on "what if" our clients D&D a folder, and it would be great if an error returns when files are dropped. I was wondering if Aras has any way of determining if the dragged object is a file or a folder/directory.

    We are also looking if there's any library we can use from the Client files, and how to use them.