Upload multiple files does not work correclty - SFUploader

I use the code from the SFUploader Example. But for some reason args.Files always contain one file. What could be the reason? AllowMultiple="true" AutoUpload="true" did not help.

@using Syncfusion.Blazor.Inputs
<SfUploader AutoUpload="true">
      <UploaderEvents ValueChange="@OnChange"></UploaderEvents>
</SfUploader>
@code {
    private async Task OnChange(UploadChangeEventArgs args)
    {
        try
        {
            foreach (var file in args.Files)
            {
                var path = @"" + file.FileInfo.Name;
                FileStream filestream = new FileStream(path, FileMode.Create, FileAccess.Write);
                await file.File.OpenReadStream(long.MaxValue).CopyToAsync(filestream);
                filestream.Close();
            }
        }
        catch (Exception ex)
        {
            Console.WriteLine(ex.Message);
        }
    }
}



4 Replies

KP Kokila Poovendran Syncfusion Team October 3, 2023 07:39 AM UTC

Hi Yaroslav Kulish,


Thank you for reaching out to us. We understand that you're experiencing issues with the SfUploader component in your Blazor project. We're here to assist you in resolving this matter.


We have reviewed your concern thoroughly and identified that there have been changes made in version 21.1.35 that may affect the behavior of the SfUploader component.


In the previous versions, the UploadChangeEventArgs included a Files property, which allowed access to a list of selected files. However, in the latest version, this behavior has changed. The ValueChange event will now be triggered for each individual file, and as a result, the UploadChangeEventArgs will provide details about a single file at a time instead of multiple files. This modification has been introduced to ensure efficient handling of file streams.


For further information regarding this change, please refer to our release noteshttps://blazor.syncfusion.com/documentation/release-notes/21.1.35?type=all#breaking-changes-7




Should you encounter any issues as a result of this update, please do not hesitate to get in touch with us.


Attachment: BlazorServerProject_8e71ebb6_f00bfb1.zip


YK Yaroslav Kulish October 3, 2023 11:29 AM UTC

Thank you a lot for detailed response!



YK Yaroslav Kulish October 3, 2023 11:37 AM UTC

And how can I get a number of selected files?



KP Kokila Poovendran Syncfusion Team October 4, 2023 08:14 AM UTC

Hi Yaroslav Kulish,


To retrieve the total number of selected files, you can utilize the "FileSelected" event. In this event handler, you can access the number of files you have selected. Please review the code snippet below for reference.


Code snippet:


@using Syncfusion.Blazor.Inputs

 

<SfUploader @ref="uploadObj" ID="UploadFiles" AutoUpload="false" AllowMultiple="true">

 

    <UploaderEvents ValueChange="@OnUploadFiles" FileSelected="OnFileSelect" ></UploaderEvents>

 

</SfUploader>

 

@code {

    SfUploader uploadObj;

 

    private async Task OnUploadFiles(UploadChangeEventArgs args)

    {

 

    }

 

     private void OnFileSelect(SelectedEventArgs args)

    {

        // You can retrieve the total number of selected files using "args.FilesData"

    }
}


You can find more information about this API in the official documentation: https://help.syncfusion.com/cr/blazor/Syncfusion.Blazor.Inputs.UploaderEvents.html#Syncfusion_Blazor_Inputs_UploaderEvents_FileSelected


If you have any further questions or need additional assistance, please don't hesitate to ask.


Regards,

Kokila Poovendran.


Loader.
Up arrow icon