Restricting uploading files based on its extension

23 Nov 20172 minutes to read

Allow Extension

Files are filtered before they are uploaded. You can select the files to be filtered by using browse button. The extensionsAllow property allows upload of the selected extensions only. You can give multiple extensions by using comma (,). The data type is string.

NOTE

Prepend dot (.) symbol with extension like “.pdf”.

The following steps explain the configuration of extensionsAllow property in Uploadbox.

In the HTML page, add the <div> element to configure the Uploadbox element.

  • HTML
  • <div id="Uploadbox"></div>
  • JS
  • // Initializes the control in JavaScript.
            $(function () {
                //Declaration.
                $("#Uploadbox").ejUploadbox({
                    saveUrl: "saveFiles.ashx",
                    removeUrl: "removeFiles.ashx",
                    extensionsAllow: ".docx, .pdf"
                });
            });

    For JS, configure saveFiles.ashx and removeFiles.ashx files as mentioned in the Save file action and Remove file action respectively.

    Deny Extension

    Files are filtered before they are uploaded. You can select the files to be filtered by using browse button. The extensionsDeny property denies upload of the selected extensions. You can give multiple extensions by using comma (,). The data type is string.

    NOTE

    Prepend dot (.) symbol with extension like “.pdf”.

    The following steps explain the configuration of extensionsDeny property in Uploadbox

    In the HTML page, add the <div> element to configure the Uploadbox element.

  • HTML
  • <div id="Uploadbox"></div>
  • JS
  • $(function () {
                //Declaration.
                $("#Uploadbox").ejUploadbox({
                    saveUrl: "saveFiles.ashx",
                    removeUrl: "removeFiles.ashx",
                    extensionsDeny: ".docx, .pdf"
                });
            });

    For JS, configure saveFiles.ashx and removeFiles.ashx files as mentioned in the Save file action and Remove file action respectively.

    NOTE

    When extensionsDeny and extensionsAllow properties have same file extension, the extension will be allowed.