Check the MIME type of file before upload it

25 Feb 20221 minute to read

By using uploading event, you can get the file MIME type before uploading it to server.
In the below sample, file MIME type is shown in the alert box before file start to upload.

@{
    var asyncSettings = new Syncfusion.EJ2.Inputs.UploaderAsyncSettings { SaveUrl = "https://ej2.syncfusion.com/services/api/uploadbox/Save", RemoveUrl = "https://ej2.syncfusion.com/services/api/uploadbox/Remove" };
}

<div class="col-lg-8 control-section">
    <div class="control_wrapper">
        <ejs-uploader id="UploadFiles" dropArea=".control-fluid" asyncSettings="@asyncSettings" autoUpload="false" uploading="onBeforeUpload">
        </ejs-uploader>
    </div>
</div>

<script>
    function onBeforeUpload(args) {
        // get the file MIME type
        alert("File MIME type is: " + args.fileData.rawFile.type);
    }
</script>
.control_wrapper {
        max-width: 500px;
        margin: auto;
    }

    .control_wrapper .e-upload .e-upload-drag-hover {
        margin: 0;
    }

You can also explore ASP.NET Core File Upload feature tour page for its groundbreaking features. You can also explore our ASP.NET Core File Upload example to understand how to browse the files which you want to upload to the server.