How to change Status message of sfuploader programatically?

I'm using sfUploader (20.2.0.43)

<SfUploader ID="UploadFiles" AllowedExtensions=".xls, .xlsx" AllowMultiple="false">
         <UploaderEvents ValueChange="OnChange"></UploaderEvents>
</SfUploader>

I have , in code, a check for a specific filename (example.xlsx) and if the file trying to be uploaded is not named example.xlsx, it does not get uploaded. (so far so good). My issue is that it still displays that the file was uploaded successfully. I tried changing the file.FileInfo.Status but that does not work. Can you tell me how I can do this?

if (file.FileInfo.Name != "example.xlsx")
     {
          file.FileInfo.Status = "Could Not Upload File. Incorrect File Name.";
          file.FileInfo.StatusCode = "Failed";
      }
 else
      {
          continue with upload.......
      }



3 Replies

UD UdhayaKumar Duraisamy Syncfusion Team August 15, 2022 07:14 AM UTC

Hi David,


We suggest you use the BeforeUpload Event for your requirement. Please refer to the below code snippet and sample for reference.


@using Syncfusion.Blazor.Inputs

@inject IJSRuntime JSRuntime

 

<SfUploader ID="UploadFiles" AllowedExtensions=".xls, .xlsx, .txt" AllowMultiple="false">

    <UploaderEvents BeforeUpload="@BeforeUploadHandler"></UploaderEvents>

</SfUploader>

 

@code {

    private async Task BeforeUploadHandler(BeforeUploadEventArgs args)

    {

        var File = args.FilesData[0];

        if (File.Name == "File1.txt")

        {

            args.Cancel = true;

            await JSRuntime.InvokeAsync<object>("StatusMessage");

        }

       

    }

}

<script>

        function StatusMessage()

        {

            document.getElementsByClassName('e-file-status')[0].innerHTML = "Could Not Upload File. Incorrect File Name.";

            document.getElementsByClassName('e-file-status')[0].style.color = "red";

        }

    </script>


Sample : https://www.syncfusion.com/downloads/support/directtrac/general/ze/Blaz_uploader_status_message-881847440


Kindly try the above suggestion and let us know if this meets your requirement.


Regards,

Udhaya Kumar D




DS David Smith August 15, 2022 12:39 PM UTC

Works perfectly, Thanks.



UD UdhayaKumar Duraisamy Syncfusion Team August 16, 2022 12:48 PM UTC

Hi David,


We are glad that your requirement has been fulfilled on your end. We are always happy to assist you.


Regards,

Udhaya Kumar D


Loader.
Up arrow icon