File gets null after uploading image - From 182969

I want to upload a file in SfUploader and get stream null.
did you know why ?


5 Replies

PK Priyanka Karthikeyan Syncfusion Team July 10, 2023 02:27 PM UTC

Hi Adnan Khan,


This is breaking changes in our end. Previously, the UploadChangeEventArgs.Stream property would return the memory stream. However, in this release, the UploadChangeEventArgs.Stream property will return null instead of the memory stream. This Stream property in UploadFiles class has been deprecated and will no longer be used. It will be removed in a future version.You can create a stream manually by calling OpenReadStream method. Please find the example code and sample for your reference.


private async void OnChangeImage(UploadChangeEventArgs args)

        {

        try

        {

            foreach (var file in args.Files)

            {

                var path = @"E:\" + file.FileInfo.Name;

                FileStream filestream = new FileStream(path, FileMode.Create, FileAccess.Write);

                // Calls the OpenReadStream method on the uploaded file to get a read stream

                await file.File.OpenReadStream(long.MaxValue).CopyToAsync(filestream);

                filestream.Close();

            }

        }

        catch (Exception ex)

        {

            Console.WriteLine(ex.Message);

        }

    }

Find the documentation link for your reference: https://blazor.syncfusion.com/documentation/release-notes/21.1.35?type=all#file-upload


Regards,

Priyanka K



AK Adnan Khan replied to Priyanka Karthikeyan July 11, 2023 11:25 AM UTC

Hi Priyanka Karthikeyan

Can you please tell me why we are using Path.
If I don't want to use Path and server side.
 



KP Kokila Poovendran Syncfusion Team July 26, 2023 03:28 PM UTC

Hi Adnan Khan,


We apologize for any inconvenience you may have experienced. The path is used to specify where the uploaded image is placed. The File Uploader component in our Blazor application allows users to upload files and folders using the following two methods:


If you facing any problem, could you please share the sample or code snippet that replicates the reported issue? Based on that, we will check and provide a prompt solution. Kindly get back to us with the requested details.



ÀL À la mode Clothing Outlet replied to Priyanka Karthikeyan November 18, 2024 03:32 PM UTC

args.Files returns null for me. kindly assist

Image_7265_1731943948598




PK Priyanka Karthikeyan Syncfusion Team November 25, 2024 05:29 AM UTC

Hi Adnan Khan,


Thank you for the update and for sharing the image. Based on the provided information, it appears that you have enabled the AsyncSettings in your implementation.

When AsyncSettings is used, the files are directly sent to the server through the configured SaveUrl, and the file handling is managed on the server side. As a result, the files are not accessible in the ValueChange event on the client side, which is why you encountered a null reference exception when trying to access the files in this event.

This behavior is the intended and default functionality of the component in asynchronous mode. In contrast, when AsyncSettings is not used, the file handling is performed on the client side, allowing the files to be accessed directly within the ValueChange event.

We truly appreciate your understanding and cooperation regarding this behavior. If you need further assistance or clarification, please don’t hesitate to reach out. We’re here to help!


Regards,

Priyanka K


Loader.
Up arrow icon