file-uploadblazorblazor-server-sideblazor-editform

Upload files using EditForm in Blazor Server?


I am using Blazor Server-Side and want to upload some files. I don't need any progress bar or so and only want to upload the files when the EditForm is submitted. The popular solutions I found until now (Synfusion Blazor File Upload, Steve Sandersons File Upload) upload files once a file is selected, not on the EditFormsubmit. Can't I just use input type="file" in HTML for my simple case? How exactly would I do that with an EditForm and how would I receive the file on the server side?


Solution

  • Steve Sandersons File Upload works, in

    void HandleFileSelected(IFileListEntry[] files)
    {
        // Do something with the files, e.g., read them
    }
    

    simply store the files are and access IFileListEntry.Data when the form is submitted. No need to read the stream immediately in HandleFileSelected.