RadzenUpload Class

A file upload component with progress tracking, multiple file support, and drag-and-drop capability. RadzenUpload provides a full-featured file upload interface with automatic or manual upload, server communication, and comprehensive event handling. Handles file selection and upload to a server endpoint with automatic upload on file selection or manual triggering via Upload() method, real-time upload progress with percentage and bytes loaded, file type restriction via Accept property (MIME types or extensions), custom authentication or HTTP headers, Complete/Error/Progress/Change events for tracking upload lifecycle, automatic image preview for image files, file removal support, and built-in drag-and-drop for file selection. Uploads files to the URL endpoint via HTTP POST multipart/form-data. Server-side endpoint must accept file uploads and return appropriate responses.

Inheritance

Object

ComponentBase

RadzenComponent

RadzenUpload

Implements

IComponent

IHandleEvent

IHandleAfterRender

Namespace: Radzen.Blazor

Assembly: Radzen.Blazor.dll

Syntax

public class RadzenUpload : RadzenComponent, IComponent, IHandleEvent, IHandleAfterRender

Examples

Basic upload with auto-upload:

<RadzenUpload Url="api/upload" Change=@OnChange Complete=@OnComplete />
@code {
    void OnChange(UploadChangeEventArgs args)
        => Console.WriteLine($"Selected {args.Files?.Count() ?? 0} files");

    void OnComplete(UploadCompleteEventArgs args)
        => Console.WriteLine(args.Cancelled ? "Upload cancelled" : "Upload complete");
}

Manual upload with progress tracking:

<RadzenUpload @ref=upload Url="api/upload" Auto="false" Multiple="true" Progress=@OnProgress />
<RadzenButton Text="Upload" Click=@(() => upload.Upload()) />
@code {
    RadzenUpload upload;
    void OnProgress(UploadProgressArgs args)
    {
        Console.WriteLine($"Progress: {args.Progress}% ({args.Loaded}/{args.Total} bytes)");
    }
}

Upload with file type filtering:

<RadzenUpload Url="api/upload/images" Accept="image/*" MaxFileSize="5000000" />

Constructors

RadzenUploadlink

A file upload component with progress tracking, multiple file support, and drag-and-drop capability. RadzenUpload provides a full-featured file upload interface with automatic or manual upload, server communication, and comprehensive event handling. Handles file selection and upload to a server endpoint with automatic upload on file selection or manual triggering via Upload() method, real-time upload progress with percentage and bytes loaded, file type restriction via Accept property (MIME types or extensions), custom authentication or HTTP headers, Complete/Error/Progress/Change events for tracking upload lifecycle, automatic image preview for image files, file removal support, and built-in drag-and-drop for file selection. Uploads files to the URL endpoint via HTTP POST multipart/form-data. Server-side endpoint must accept file uploads and return appropriate responses.

Declaration
public RadzenUpload()

Fields

fileUploadlink

Gets file input reference.

Declaration
protected ElementReference fileUpload

Properties

Acceptlink

Gets or sets the accepted MIME types.

Declaration
public string Accept { get; set; }
Property Value
Type Description
stringGets or sets the accepted MIME types.

Autolink

Gets or sets a value indicating whether this RadzenUpload upload is automatic.

Declaration
public bool Auto { get; set; }
Property Value
Type Description
boolGets or sets a value indicating whether this RadzenUpload upload is automatic.

Changelink

Gets or sets the change callback.

Declaration
public EventCallback<UploadChangeEventArgs> Change { get; set; }
Property Value
Type Description
EventCallback<UploadChangeEventArgs>Gets or sets the change callback.

ChildContentlink

Gets or sets the child content.

Declaration
public RenderFragment ChildContent { get; set; }
Property Value
Type Description
RenderFragmentGets or sets the child content.

ChooseTextlink

Gets or sets the choose button text.

Declaration
public string ChooseText { get; set; }
Property Value
Type Description
stringGets or sets the choose button text.

Completelink

Gets or sets the complete callback.

Declaration
public EventCallback<UploadCompleteEventArgs> Complete { get; set; }
Property Value
Type Description
EventCallback<UploadCompleteEventArgs>Gets or sets the complete callback.

DeleteTextlink

Gets or sets the choose button text.

Declaration
public string DeleteText { get; set; }
Property Value
Type Description
stringGets or sets the choose button text.

Disabledlink

Gets or sets a value indicating whether this RadzenUpload is disabled.

Declaration
public bool Disabled { get; set; }
Property Value
Type Description
boolGets or sets a value indicating whether this RadzenUpload is disabled.

Errorlink

Gets or sets the error callback.

Declaration
public EventCallback<UploadErrorEventArgs> Error { get; set; }
Property Value
Type Description
EventCallback<UploadErrorEventArgs>Gets or sets the error callback.

HasValuelink

Gets a value indicating whether this instance has value.

Declaration
public bool HasValue { get; }
Property Value
Type Description
boolGets a value indicating whether this instance has value.

Iconlink

Gets or sets the icon.

Declaration
public string Icon { get; set; }
Property Value
Type Description
stringGets or sets the icon.

IconColorlink

Gets or sets the icon color.

Declaration
public string IconColor { get; set; }
Property Value
Type Description
stringGets or sets the icon color.

ImageAlternateTextlink

Gets or sets the text.

Declaration
public string ImageAlternateText { get; set; }
Property Value
Type Description
stringGets or sets the text.

InputAttributeslink

Specifies additional custom attributes that will be rendered by the input.

Declaration
public IReadOnlyDictionary<string, object> InputAttributes { get; set; }
Property Value
Type Description
IReadOnlyDictionary<string, object>Specifies additional custom attributes that will be rendered by the input.

MaxFileCountlink

Gets or sets the maximum number of files.

Declaration
public int MaxFileCount { get; set; }
Property Value
Type Description
intGets or sets the maximum number of files.

Methodlink

Specifies the HTTP method used for uploading files to the defined Url endpoint. Common values are POST (default) and PUT. If the parameter is not set, this property is ignored. Defaults to POST.

Declaration
public string Method { get; set; }
Property Value
Type Description
stringSpecifies the HTTP method used for uploading files to the defined Url endpoint. Common values are POST (default) and PUT. If the parameter is not set, this property is ignored. Defaults to POST.

Multiplelink

Gets or sets a value indicating whether this RadzenUpload is multiple.

Declaration
public bool Multiple { get; set; }
Property Value
Type Description
boolGets or sets a value indicating whether this RadzenUpload is multiple.

Namelink

Gets or sets the name.

Declaration
public string Name { get; set; }
Property Value
Type Description
stringGets or sets the name.

ParameterNamelink

Gets or sets the parameter name. If not set 'file' parameter name will be used for single file and 'files' for multiple files.

Declaration
public string ParameterName { get; set; }
Property Value
Type Description
stringGets or sets the parameter name. If not set 'file' parameter name will be used for single file and 'files' for multiple files.

Progresslink

Gets or sets the progress callback.

Declaration
public EventCallback<UploadProgressArgs> Progress { get; set; }
Property Value
Type Description
EventCallback<UploadProgressArgs>Gets or sets the progress callback.

Streamlink

Enables streaming upload mode for large files to the specified Url. When true, files are uploaded as raw binary streams instead of multipart/form-data. Only a single file can be uploaded at a time in streaming mode. When false (default), files are uploaded as multipart/form-data (standard form upload), and multiple files can be uploaded simultaneously if is enabled. This property is ignored if is not set.

Declaration
public bool Stream { get; set; }
Property Value
Type Description
boolEnables streaming upload mode for large files to the specified Url. When true, files are uploaded as raw binary streams instead of multipart/form-data. Only a single file can be uploaded at a time in streaming mode. When false (default), files are uploaded as multipart/form-data (standard form upload), and multiple files can be uploaded simultaneously if is enabled. This property is ignored if is not set.

Urllink

Gets or sets the URL.

Declaration
public string Url { get; set; }
Property Value
Type Description
stringGets or sets the URL.

Methods

BuildRenderTreelink

Declaration
protected override void BuildRenderTree(Rendering.RenderTreeBuilder __builder)
Parameters
Type Name Description
Rendering.RenderTreeBuilder __builder

ClearFileslink

Clear selected file(s) from the upload selection

Declaration
public Task ClearFiles()
Returns
Type Description
Task

CreateUploadChangeEventArgslink

Creates the upload change event args.

Declaration
public UploadChangeEventArgs CreateUploadChangeEventArgs(IEnumerable<FileInfo> files)
Parameters
Type Name Description
IEnumerable<FileInfo> files
Returns
Type Description
UploadChangeEventArgs

GetComponentCssClasslink

Declaration
protected override string GetComponentCssClass()
Returns
Type Description
string

GetHeaderslink

Gets the headers.

Declaration
public IDictionary<string, string> GetHeaders()
Returns
Type Description
IDictionary<string, string>IDictionary<System.String, System.String>.

OnAfterRenderAsynclink

Declaration
protected override Task OnAfterRenderAsync(bool firstRender)
Parameters
Type Name Description
bool firstRender
Returns
Type Description
Task

OnChangelink

Called on file change.

Declaration
public Task OnChange(IEnumerable<PreviewFileInfo> files)
Parameters
Type Name Description
IEnumerable<PreviewFileInfo> files The files.
Returns
Type Description
Task

OnCompletelink

Called when upload is complete.

Declaration
public Task OnComplete(string response, bool cancelled)
Parameters
Type Name Description
string response The response.
bool cancelled Flag indicating if the upload was cancelled
Returns
Type Description
Task

OnErrorlink

Called on upload error.

Declaration
public Task OnError(string error)
Parameters
Type Name Description
string error The error.
Returns
Type Description
Task

OnProgresslink

Called on progress.

Declaration
public Task<bool> OnProgress(int progress, long loaded, long total, IEnumerable<FileInfo> files, bool cancel)
Parameters
Type Name Description
int progress The progress.
long loaded The loaded.
long total The total.
IEnumerable<FileInfo> files The files.
bool cancel The cancelled state.
Returns
Type Description
Task<bool>

OnRemovelink

Called on file remove.

Declaration
protected Task OnRemove(PreviewFileInfo file, bool fireChangeEvent)
Parameters
Type Name Description
PreviewFileInfo file The file.
bool fireChangeEvent If the linked Change event should be fired as a result of this removal (default: true)
Returns
Type Description
Task

RemoveFilelink

Called on file remove.

Declaration
public Task RemoveFile(string fileName, bool ignoreCase)
Parameters
Type Name Description
string fileName The name of the file to remove.
bool ignoreCase Specify true is file name casing should be ignored (default: false)
Returns
Type Description
Task

SetParametersAsynclink

Declaration
public override Task SetParametersAsync(ParameterView parameters)
Parameters
Type Name Description
ParameterView parameters
Returns
Type Description
Task

Uploadlink

Uploads this instance selected files.

Declaration
public Task Upload()
Returns
Type Description
Task
An error has occurred. This app may no longer respond until reloaded. Reload 🗙