BlazorBasics.InputFileExtended 3.9.46

dotnet add package BlazorBasics.InputFileExtended --version 3.9.46
                    
NuGet\Install-Package BlazorBasics.InputFileExtended -Version 3.9.46
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="BlazorBasics.InputFileExtended" Version="3.9.46" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="BlazorBasics.InputFileExtended" Version="3.9.46" />
                    
Directory.Packages.props
<PackageReference Include="BlazorBasics.InputFileExtended" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add BlazorBasics.InputFileExtended --version 3.9.46
                    
#r "nuget: BlazorBasics.InputFileExtended, 3.9.46"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package BlazorBasics.InputFileExtended@3.9.46
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=BlazorBasics.InputFileExtended&version=3.9.46
                    
Install as a Cake Addin
#tool nuget:?package=BlazorBasics.InputFileExtended&version=3.9.46
                    
Install as a Cake Tool

Nuget Nuget

BlazorBasics.InputFileExtended

Extend the traditional InputFile component with more options like drag and drop, copy and paste, preview, upload button, streaming for big files and a rich set of events — with less coding for everyone.

Official web documentation and live examples.

Supported target frameworks: .NET 8, .NET 9 and .NET 10.

Table of contents

Features

  • Standard file selection like the native InputFile.
  • Drag and drop files into a drop zone.
  • Copy and paste files / images from the clipboard.
  • Image preview of the selected files.
  • Optional upload button with before / after submit hooks.
  • Auto upload after selection (one by one as an event callback).
  • Streaming mode to upload very big files by chunks.
  • Maximum number of files and maximum file size validation with detailed exceptions.
  • Rich event model: OnSelected, OnChange, OnAddFile, OnError.
  • Full UI customization through RenderFragment parameters.
  • Works inside an EditForm (validated through the cascading EditContext).

Installation

Install from NuGet:

dotnet add package BlazorBasics.InputFileExtended

Import the namespace adding this line to _Imports.razor:

@using BlazorBasics.InputFileExtended

Tip: you can also import the value objects and models namespaces to avoid the long fully-qualified names used in some examples below:

@using BlazorBasics.InputFileExtended.ValueObjects
@using BlazorBasics.InputFileExtended.Models

Quick start

@using BlazorBasics.InputFileExtended

<InputFileComponent OnChange="LoadFiles" />

@code {
    private void LoadFiles(FilesUploadEventArgs e)
    {
        // e.Files  -> List<FileUploadContent>
        // e.Count  -> number of files
        // e.Size   -> total size in bytes
        // e.Action -> EventAction (Added, Removed, ...)
    }
}

Drag and drop

@using BlazorBasics.InputFileExtended
@using BlazorBasics.InputFileExtended.ValueObjects

<InputFileComponent Parameters="Parameters" OnChange="LoadFiles" />

@code {
    InputFileParameters Parameters = new()
    {
        DragAndDropOptions = new DragAndDropOptions
        {
            CanDropFiles = true
        }
    };

    private void LoadFiles(FilesUploadEventArgs e)
    {
        // ...
    }
}

Copy and paste

Paste works independently of drag and drop — you can enable either or both.

@using BlazorBasics.InputFileExtended
@using BlazorBasics.InputFileExtended.ValueObjects

<InputFileComponent Parameters="Parameters" OnChange="LoadFiles" />

@code {
    InputFileParameters Parameters = new()
    {
        AllowPasteFiles = true
    };

    private void LoadFiles(FilesUploadEventArgs e)
    {
        // ...
    }
}

Image preview

@using BlazorBasics.InputFileExtended
@using BlazorBasics.InputFileExtended.ValueObjects

<InputFileComponent Parameters="Parameters" OnChange="LoadFiles" />

@code {
    InputFileParameters Parameters = new()
    {
        PreviewOptions = new PreviewOptions
        {
            IsImage = true,
            ShowPreview = true,
            // Show a delete button even when there is no callback wired
            CanDeleteIfNotCallBack = true
        }
    };

    private void LoadFiles(FilesUploadEventArgs e) { }
}

When PreviewOptions.IsImage is true and no InputFileTypes is set, the input automatically restricts the selection to image/*.

Each selected file exposes a ready-to-use ImageDataUrl you can bind directly to an img element:

@foreach (var file in files)
{
    <img src="@file.ImageDataUrl" alt="@file.Name" />
}

Upload button

When you show the upload button, ButtonOptions.OnSubmit is required.

@using BlazorBasics.InputFileExtended
@using BlazorBasics.InputFileExtended.ValueObjects
@using BlazorBasics.InputFileExtended.Models

<InputFileComponent Parameters="Parameters" />

@code {
    InputFileParameters Parameters;

    protected override void OnInitialized()
    {
        Parameters = new InputFileParameters
        {
            ButtonOptions = new ButtonOptions
            {
                ButtonShow = true,
                ButtonTitle = "Upload",
                CleanOnSuccessUpload = true,
                OnBeforeSubmit = BeforeSubmit,
                OnSubmit = UploadFiles,
                OnAfterSubmit = AfterSubmit
            }
        };
    }

    Task BeforeSubmit(IReadOnlyList<FileUploadContent> files)
    {
        // e.g. show a spinner
        return Task.CompletedTask;
    }

    async Task UploadFiles(IReadOnlyList<FileUploadContent> files)
    {
        // process your upload, you have access to each file bytes
        foreach (var file in files)
        {
            byte[] bytes = file.FileBytes;
            // send to your API / storage ...
        }
        await Task.Delay(1);
    }

    Task AfterSubmit(bool isValid)
    {
        // e.g. hide the spinner, show a toast
        return Task.CompletedTask;
    }
}

Inside an EditForm, the button submit is validated against the cascading EditContext automatically. You can also trigger the submit programmatically by calling the public FormSave() method (see Public members).

Auto upload

With AutoUpload = true each file is uploaded right after it is selected (handled one by one through the submit callback), without showing a button.

@using BlazorBasics.InputFileExtended
@using BlazorBasics.InputFileExtended.ValueObjects
@using BlazorBasics.InputFileExtended.Models

<InputFileComponent Parameters="Parameters" />

@code {
    InputFileParameters Parameters;

    protected override void OnInitialized()
    {
        Parameters = new InputFileParameters
        {
            ButtonOptions = new ButtonOptions
            {
                AutoUpload = true,
                OnSubmit = UploadFiles
            }
        };
    }

    async Task UploadFiles(IReadOnlyList<FileUploadContent> files)
    {
        // ...
        await Task.Delay(1);
    }
}

Streaming big files

Enable EnableStreaming to handle very big files by chunks. In this mode the component reads only the file metadata on the .NET side and relies on the JavaScript layer to stream the content.

@using BlazorBasics.InputFileExtended
@using BlazorBasics.InputFileExtended.ValueObjects

<InputFileComponent Parameters="Parameters" OnChange="LoadFiles" />

@code {
    InputFileParameters Parameters = new()
    {
        EnableStreaming = true,
        MaxFileSize = 1024L * 1024L * 500L // 500 MB
    };

    private void LoadFiles(FilesUploadEventArgs e) { }
}

Events

All events are exposed as EventCallback parameters on InputFileComponent.

Event Payload When it is raised
OnSelected FilesUploadEventArgs The instant files are picked, before any byte is read. Metadata only.
OnChange FilesUploadEventArgs After files are processed / added or removed from the container.
OnAddFile FileUploadEventArgs Per each file added (single file payload).
OnError InputFileException When a validation or upload error occurs.

OnSelected

New. Raised the instant a selection is known (file name, size and content type), before any byte is read from disk. Use it to give immediate UI feedback (for example a "processing…" indicator) for heavy files such as videos, whose read can take several seconds.

The FileUploadContent items in the payload carry metadata onlyFileBytes and ImageDataUrl are not populated yet. The reported Action is EventAction.Change.

Internally, when JavaScript is available, OnSelected fires from a native change listener the moment files are picked (even before Blazor's own change pipeline runs). If JS is unavailable it gracefully falls back to firing during the in-Change notification.

@using BlazorBasics.InputFileExtended
@using BlazorBasics.InputFileExtended.Models

<InputFileComponent OnSelected="HandleSelected" OnChange="HandleChange" />

@if (isProcessing)
{
    <p>Processing @pendingCount file(s)…</p>
}

@code {
    bool isProcessing;
    int pendingCount;

    // Fires immediately when the user picks files (metadata only, no bytes yet)
    private void HandleSelected(FilesUploadEventArgs e)
    {
        isProcessing = true;
        pendingCount = e.Count;

        foreach (var file in e.Files)
        {
            // file.Name, file.Size, file.ContentType, file.LastModified available
            // file.FileBytes is NOT available here yet
        }
    }

    // Fires later, once bytes are read and the files are added
    private void HandleChange(FilesUploadEventArgs e)
    {
        isProcessing = false;
        // Now e.Files contain the bytes (file.FileBytes / file.ImageDataUrl)
    }
}

OnChange

Raised once the selected files have been processed and added to the container, and also when a file is removed from the collection. The FileUploadContent items now contain the bytes.

<InputFileComponent OnChange="HandleChange" />

@code {
    private void HandleChange(FilesUploadEventArgs e)
    {
        switch (e.Action)
        {
            case EventAction.Added:   /* files added */    break;
            case EventAction.Removed: /* a file removed */ break;
        }
    }
}

OnAddFile

Raised per each individual file added, with a single-file payload. Useful together with auto upload to react file by file.

<InputFileComponent OnAddFile="HandleAddFile" />

@code {
    private void HandleAddFile(FileUploadEventArgs e)
    {
        FileUploadContent file = e.File;
        Guid id = e.FileId;
        EventAction action = e.Action;
    }
}

OnError

Raised when a validation rule (max file count, max size) or an upload fails. The InputFileException exposes detailed information about what went wrong.

<InputFileComponent Parameters="Parameters" OnError="HandleError" />

@code {
    InputFileParameters Parameters = new()
    {
        MaxUploatedFiles = 3,
        MaxFileSize = 1_048_576 // 1 MB
    };

    private void HandleError(InputFileException ex)
    {
        // ex.ExceptionType -> Generic | MaxCount | MaxSize (Flags)
        // ex.FilesCount, ex.FileBytes, ex.FileMbBytes
        // ex.MaxFilesAllowed, ex.MaxFileBytes, ex.MaxFileMbBytes
        // ex.Files -> files affected
        if (ex.ExceptionType.HasFlag(ExceptionType.MaxSize))
        {
            // show a friendly "file too big" message
        }
    }
}

If you do not wire OnError, the component shows the error message inline by itself.

Configuration reference

InputFileParameters

Property Type Default Description
ShowFileList bool true Show / hide the list of selected files.
AllowPasteFiles bool false Enable copy and paste of files / images.
MultiFile bool true Allow selecting multiple files.
MaxUploatedFiles int 5 Maximum number of files allowed.
MaxFileSize long 1536000 Maximum size per file, in bytes.
InputFileTypes string "" Accepted file types, e.g. image/*.
InputFileCss string "" CSS class for the input file element.
ButtonOptions ButtonOptions new() Upload button configuration.
PreviewOptions PreviewOptions new() Image / preview configuration.
DragAndDropOptions DragAndDropOptions new() Drag and drop configuration.
OnShouldCancelClick Func<Task<bool>> null Run code before the input click; return true to cancel it.
EnableStreaming bool false Enable streaming mode for big files.

ButtonOptions

Property Type Default Description
OnBeforeSubmit Func<IReadOnlyList<FileUploadContent>, Task> null Run code before submit.
OnSubmit Func<IReadOnlyList<FileUploadContent>, Task> null Submit handler. Required when ButtonShow is true.
OnAfterSubmit Func<bool, Task> null Run code after submit (receives validity).
ButtonShow bool false Show the upload button.
ButtonCss string "input-file button-upload" CSS class for the button.
ButtonTitle string "" Button text.
ButtonType ButtonType Button Button or Submit.
AutoUpload bool false Upload automatically after selection.
CleanOnSuccessUpload bool true Clear files after a successful upload.

PreviewOptions

Property Type Default Description
IsImage bool true Indicates the files are images.
ShowPreview bool false Render an image preview of each file.
PreviewWrapperCss string "image-container" CSS class for the preview wrapper.
ImagePreviewCss string "image" CSS class for the preview image.
CanDeleteIfNotCallBack bool false Show a delete button even when no callback is set.

DragAndDropOptions

Property Type Default Description
CanDropFiles bool false Enable dropping files.
DropZoneCss string "drop-zone" CSS class for the drop zone.
DroppingCss string "drop-zone-drag" CSS class while dragging over the drop zone.

Models

FileUploadContent

The full representation of an uploaded file.

Member Type Description
Name string File name.
LastModified DateTimeOffset Last modified date.
Size long Size in bytes.
ContentType string MIME type.
FileId Guid Unique identifier for the file.
ImageDataUrl string Data URL ready to be used as an img src.
FileBytes byte[] Raw file bytes.
Dispose() void Clears FileBytes to release memory.

FileBasicInfo

Now public. Lightweight metadata model (no bytes), used by the streaming / early-selection pipeline and exposed publicly so you can consume it from your own code.

Member Type Description
Name string File name.
Size long Size in bytes.
Type string MIME type.
LastModified long Last modified as Unix time (ms).
LastModifiedDateTime DateTimeOffset LastModified converted to DateTimeOffset.

FilesUploadEventArgs

Payload for OnSelected and OnChange: Files (List<FileUploadContent>), Size (long), Count (int), Action (EventAction).

FileUploadEventArgs

Payload for OnAddFile: File (FileUploadContent), FileId (Guid), Action (EventAction).

EventAction

Change, Added, Updated, Removed, Clean, Upload.

Public members of the component

Capture a reference with @ref to access these:

<InputFileComponent @ref="inputFile" Parameters="Parameters" />

@code {
    InputFileComponent inputFile;

    void ClearAll() => inputFile.Clean();
    Task Save() => inputFile.FormSave();
    Task PickFiles() => inputFile.OpenFileDialog();
}
Member Description
Files InputFileHandler exposing the managed files (e.g. to show all images).
InputFileId The generated id of the input element (useful for external CSS / JS).
Clean() Remove all selected files.
FormSave() Trigger the save / submit (validated when inside an EditForm).
OpenFileDialog() Open the file picker programmatically, without a user click.

Customizing the UI with RenderFragments

InputFileComponent exposes several RenderFragment parameters to fully customize the UI:

Parameter Type Description
InputContent RenderFragment Content shown for the file selection area.
SelectContent RenderFragment<IReadOnlyList<FileUploadContent>> Content rendered once with the whole selection.
ButtonContent RenderFragment Custom content / text for the upload button.
ChildContent RenderFragment<FileUploadContent> Content rendered per each file (used when there is no preview).
Attributes Dictionary<string, object> Additional HTML attributes (captured unmatched values).
<InputFileComponent Parameters="Parameters" OnChange="LoadFiles">
    <InputContent>
        <span>Drag your files here or click to browse</span>
    </InputContent>
    <ChildContent Context="file">
        <div class="file-row">
            <strong>@file.Name</strong> — @file.Size bytes
        </div>
    </ChildContent>
</InputFileComponent>

Made with ❤️ by DrUalcman. Issues and contributions are welcome at the GitHub repository.

Product Compatible and additional computed target framework versions.
.NET net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 is compatible.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 is compatible.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
3.9.46 0 6/16/2026
3.9.45 0 6/16/2026
3.9.44 141 6/4/2026
3.9.43 116 6/1/2026
3.9.42 104 5/29/2026
3.8.41 262 4/26/2026
3.8.40 212 3/18/2026
3.8.39 191 2/24/2026
3.8.38 156 2/15/2026
3.8.37 144 2/9/2026
3.8.36 146 2/1/2026
3.8.35 151 1/18/2026
3.7.34 134 1/17/2026
3.7.33 845 10/22/2025
3.7.32 361 6/29/2025
3.7.31 255 5/31/2025
3.7.30 1,053 10/10/2024
3.6.29 370 7/17/2024
3.5.27 5,074 3/20/2024
3.5.26 4,478 1/13/2024
Loading failed

Version 3.9.46: OnSelected now fires from a native JS change listener the instant files are picked (metadata only, before Blazor's change pipeline or any byte read) for the earliest possible UI feedback on heavy files; falls back to the in-Change notification if JS is unavailable. FileBasicInfo made public.
Version 3.9.45: Add OnSelected event raised the instant files are selected (name/size/type metadata, before reading bytes) so consumers can show immediate UI feedback for heavy files like videos. Fixed streaming mode accumulating files across selections causing false validation errors. Update dependencies.
Version 3.9.44: Fixed ExceptionType detection comparing count vs count instead of count vs bytes.
Version 3.9.43: Fixed notification on change.
Version 3.9.42: Change void to events handler events from void to Task. Removed StreamContent and replaced with byte[] in FileUploadContent object and UploadedImage property. Fixed send correct files collection to callback. Refactor how to throw exceptions. Update dependencies.
Version 3.8.41: Improve management autoupload files to handle one by one as event callback. Update dependencies.
Version 3.8.40: Fixed issue in FileUploadContent.ImageDataUrl with mime type. Improved how to return exceptions.
Version 3.8.39: Control error label only show when have error and don't have delegate.
Version 3.8.38: Add loading content when show button. Default is a normal loading or content from user button controlling the content.
Version 3.8.37: Improved SelectContent to show the content one time and also receive of FileUploadContent if user want to do some. If Preview is not selected and has ChildContent then render ChildContent per each file.
Version 3.8.36: Add new parameter EnableStreaming to keep the user posibility to upload big files by chunks. User must be implement the Javascript.
Version 3.8.35: Change callback object from int to FileUploadContent in SelectContent. Rename ToImageHTML => ImageDataUrl. Fixed issue with internal Rows param.
Version 3.7.34: Target NET 10. Update dependencies.
Version 3.7.33: Update dependencies.
Version 3.7.32: Improved how manage exceptions. Update dependencies.
Version 3.7.31: Add Net 9 support. Update licence. Update dependencies.
Version 3.7.30: Removed support for NET6 and NET7. Update nugets.
Version 3.6.29: Add Openfiledialog public method for can fired upload files with no click from user and do by code. Add Parameter to can cancel the click on the Inputfile with some code when you click on the Inputfile. Fixed and notify OnChange event when the file it's removed from the collection. Update nugets.
Version 3.5.28: Fixed null reference when try to use the context inside the unputfilecomponent to personalize the preview file.
Version 3.5.27: Fixed Parameters.InputFileTypes when is set not get a value.
Version 3.5.26: Create new component FilePreviewComponent to separate the logic when it's a preview image or only list image. Fixed don't remove error message after fix the issue and or selecte a new file. Add 2 new properties to the options. In the general InputFileCss and in PreviewOptions CanDeleteIfNotCallBack to show a delete button when no callback action set. .
Version 3.5.25: Update Nuget and NET versions
Version 3.5.24: Add 2 new Func properties in ButtonOptions. OnBeforeSubmit and OnAfterSubmit. If user want to do some code before and after submit the form.
Version 3.5.23: Add parameter to hide show the list of the files. Change Parameter buttonOptions OnSubmit to Func to return a Task bool. Removed not used injections.
Version 3.5.22: Moved from BlazorInputFileExtended to be supported by DigitalDoor. Add list of files when files are selected. Allow paste also independent if you enable drag and drop. Removed HttpClient dependency and use a delegate Task to upload with the button action.