Uploading files
The InputFile
component is a built-in Blazor component that is used to upload files into a Blazor app. It renders an HTML input
element of type file
and supplies a stream for the contents of the file. It is in the Microsoft.AspNetCore.Components.Forms
namespace.
The OnChange
event of the InputFile
component is used to set the callback that gets invoked when a file is selected. This is an example of an InputFile
component that invokes the OnChangeHandler
method when a file is selected:
<InputFile OnChange="OnChangeHandler"
accept="image/png, image/jpeg" />
This is the resulting HTML markup from the preceding example:
<input accept="image/png, image/jpeg" type="file" _bl_2="">
In the preceding HTML markup, the _bl_2
attribute is used for Blazor’s internal processing, but everything else is a typical input
element. The accept
attribute is used to filter the types of...