Class SfUploader
The Syncfusion Blazor Uploader component provides a comprehensive file upload solution with advanced features for uploading images, documents, and other files to a server. This component extends the functionality of HTML5 file upload with multiple file selection, automatic upload, drag and drop support, progress tracking, file preloading, and validation capabilities.
Implements
Inherited Members
Namespace: Syncfusion.Blazor.Toolkit.Inputs
Assembly: Syncfusion.Blazor.Toolkit.dll
Syntax
public class SfUploader : SfBaseComponent, IAsyncDisposable
Remarks
The SfUploader component offers a rich set of features including:
- Multiple file selection and upload
- Drag and drop functionality for intuitive file selection
- Automatic upload with configurable settings
- Progress bar visualization during upload operations
- File validation with size and type restrictions
- Template customization for enhanced user experience
- Chunk upload support for large files
- Resume and pause upload functionality
Examples
Basic implementation of the SfUploader component:
<SfUploader ID="fileUpload" AutoUpload="false" OnUploadStart="@OnFileUploadStart" ValueChange="@OnChange">
<UploaderAsyncSettings SaveUrl="api/SampleData/Save" RemoveUrl="api/SampleData/Remove" />
</SfUploader>
@code {
private void OnFileUploadStart(UploadingEventArgs args)
{
// Handle upload start logic
}
private void OnChange(UploadChangeEventArgs args)
{
// Handle file selection changes
}
}
Constructors
SfUploader()
Declaration
public SfUploader()
Properties
AllowedExtensions
Gets or sets the extensions of the file types allowed in the Uploader component, passing the extensions with the comma separators.
Declaration
public string AllowedExtensions { get; set; }
Property Value
| Type | Description |
|---|---|
| System.String | Accepts the string value. The default value is empty. |
Remarks
For example, if you want to upload specific image files, pass the property as ".jpg" and ".png."
Examples
@using Syncfusion.Blazor.Inputs
<SfUploader ID="UploadFiles" AllowedExtensions=".jpg, .png">
<UploaderAsyncSettings SaveUrl="api/SampleData/Save" RemoveUrl="api/SampleData/Remove"/>
</SfUploader>
AllowMultiple
Gets or sets a value that indicates whether multiple files can be browsed or dropped simultaneously in the SfUploader component.
Declaration
public bool AllowMultiple { get; set; }
Property Value
| Type | Description |
|---|---|
| System.Boolean |
|
AutoUpload
Gets or sets whether the SfUploader component initiates automatic upload after the files are selected.
Declaration
public bool AutoUpload { get; set; }
Property Value
| Type | Description |
|---|---|
| System.Boolean |
|
Remarks
If you want to manipulate the files before uploading to server, disable the AutoUpload property.
Examples
@using Syncfusion.Blazor.Inputs
<SfUploader ID="UploadFiles" AutoUpload="false">
<UploaderAsyncSettings SaveUrl="api/SampleData/Save" RemoveUrl="api/SampleData/Remove" />
</SfUploader>
BeforeRemove
Gets or sets the event callback that will be invoked before removing a file from the server. This event allows you to cancel the removal operation or perform custom actions before file deletion.
Declaration
public EventCallback<BeforeRemoveEventArgs> BeforeRemove { get; set; }
Property Value
| Type | Description |
|---|---|
| Microsoft.AspNetCore.Components.EventCallback<BeforeRemoveEventArgs> | An Microsoft.AspNetCore.Components.EventCallback<> that handles the before remove event. |
BeforeUpload
Gets or sets the event callback that will be invoked before the uploading process starts.
Declaration
public EventCallback<BeforeUploadEventArgs> BeforeUpload { get; set; }
Property Value
| Type | Description |
|---|---|
| Microsoft.AspNetCore.Components.EventCallback<BeforeUploadEventArgs> | An Microsoft.AspNetCore.Components.EventCallback<> that handles the before upload event. |
Remarks
You can pass additional data with the file uploading request in the CustomFormData argument.
Examples
@using Syncfusion.Blazor.Inputs
<SfUploader BeforeUpload="@BeforeUploadHandler">
</SfUploader>
@code {
public void BeforeUploadHandler(BeforeUploadEventArgs args) {
var accessToken = "Authorization_token";
args.CurrentRequest = new List<object> { new { Authorization = accessToken } };
}
}
Created
Gets or sets the event callback that will be invoked when the SfUploader component has been created and initialized. This event is useful for performing initialization tasks after the component is ready.
Declaration
public EventCallback<object> Created { get; set; }
Property Value
| Type | Description |
|---|---|
| Microsoft.AspNetCore.Components.EventCallback<System.Object> | An Microsoft.AspNetCore.Components.EventCallback<> that handles the component creation event. |
CssClass
Gets or sets one or more CSS classes that can be used to customize the appearance of a file upload component.
Declaration
public string CssClass { get; set; }
Property Value
| Type | Description |
|---|---|
| System.String | Accepts the CSS class string separated by space to customize the appearance of component. |
Remarks
One or more custom CSS classes can be added to a file upload.
Examples
@using Syncfusion.Blazor.Inputs
<SfUploader ID="UploadFiles" CssClass="custom-uploader my-class">
<UploaderAsyncSettings SaveUrl="api/SampleData/Save" RemoveUrl="api/SampleData/Remove" />
</SfUploader>
DirectoryUpload
Gets or sets a value indicating whether folders can be browsed and uploaded in the file upload component.
Declaration
public bool DirectoryUpload { get; set; }
Property Value
| Type | Description |
|---|---|
| System.Boolean |
|
Disabled
Gets or sets a value that indicates whether the SfUploader component allows user interaction.
Declaration
public bool Disabled { get; set; }
Property Value
| Type | Description |
|---|---|
| System.Boolean |
|
DropArea
Gets or sets the custom file drop target element selectors to handle file upload on drag-and-drop action.
Declaration
public string DropArea { get; set; }
Property Value
| Type | Description |
|---|---|
| System.String | Accepts the target element selector string. |
Remarks
By default, the file upload component creates a container element around the file input that will act as a drop target.
Examples
@using Syncfusion.Blazor.Inputs
<SfUploader DropArea="#CustomDropArea" >
<UploaderAsyncSettings SaveUrl="api/SampleData/Save" RemoveUrl="api/SampleData/Remove" />
</SfUploader>
<div id="CustomDropArea" style="width:200px; height:200px; border:dashed 1px" ></div>
DropEffect
Gets or sets the cursor displayed while dragging the file into the SfUploader component. It indicates which type of operation will occur.
Declaration
public DropEffect DropEffect { get; set; }
Property Value
| Type | Description |
|---|---|
| DropEffect | One of the |
Remarks
The DropEffect property can be set to one of the following values:
- Copy
- Move
- Link
- None
Examples
@using Syncfusion.Blazor.Inputs
<SfUploader ID="UploadFiles" DropEffect="DropEffect.Copy">
<UploaderAsyncSettings SaveUrl="api/SampleData/Save" RemoveUrl="api/SampleData/Remove" />
</SfUploader>
EnableHtmlSanitizer
Gets or sets a value indicating whether to prevent cross-site scripting code in filenames.
Declaration
public bool EnableHtmlSanitizer { get; set; }
Property Value
| Type | Description |
|---|---|
| System.Boolean |
|
Remarks
The EnableHtmlSanitizer property removes cross-site scripting code or functions from the filename and shows a validation error message to the user.
Examples
@using Syncfusion.Blazor.Inputs
<SfUploader ID="UploadFiles" EnableHtmlSanitizer="false">
<UploaderAsyncSettings SaveUrl="api/SampleData/Save" RemoveUrl="api/SampleData/Remove" />
</SfUploader>
EnablePersistence
Gets or sets a value indicating whether the file upload state should be persisted on page reload. If enabled, the state of uploaded or selected files will be maintained.
Declaration
public bool EnablePersistence { get; set; }
Property Value
| Type | Description |
|---|---|
| System.Boolean |
|
FileSelected
Gets or sets the event callback that will be invoked after selecting or dropping files in the SfUploader component. This event provides information about the newly selected files and allows validation before upload.
Declaration
public EventCallback<SelectedEventArgs> FileSelected { get; set; }
Property Value
| Type | Description |
|---|---|
| Microsoft.AspNetCore.Components.EventCallback<SelectedEventArgs> | An Microsoft.AspNetCore.Components.EventCallback<> that handles file selection events. |
HtmlAttributes
Gets or sets an additional html attributes such as styles, class, and more to add the root element.
Declaration
public Dictionary<string, object> HtmlAttributes { get; set; }
Property Value
| Type | Description |
|---|---|
| System.Collections.Generic.Dictionary<System.String, System.Object> | A dictionary of additional HTML attributes for the root element of the component. |
Remarks
If you configured both property and equivalent html attributes, the component considers the property value.
Examples
@using Syncfusion.Blazor.Inputs
<SfUploader ID="UploadFiles" HtmlAttributes="@HtmlAttribute">
<UploaderAsyncSettings SaveUrl="api/SampleData/Save" RemoveUrl="api/SampleData/Remove" />
</SfUploader>
@code {
Dictionary<string, object> HtmlAttribute = new Dictionary<string, object>() {
{"disabled","true" }
};
}
HttpClientInstance
Gets or sets the System.Net.Http.HttpClient instance used by the SfUploader component for performing upload and remove operations.
Declaration
public HttpClient HttpClientInstance { get; set; }
Property Value
| Type | Description |
|---|---|
| System.Net.Http.HttpClient | The System.Net.Http.HttpClient instance that handles HTTP requests for the SfUploader component. If not set, the component will use the globally injected System.Net.Http.HttpClient instance from the application. |
Remarks
Use this property to bind a custom System.Net.Http.HttpClient instance to the SfUploader component. This allows for centralized management of HTTP configurations such as headers, base addresses, and timeouts, ensuring consistent HTTP settings across your application.
If HttpClientInstance is not specified, the component defaults to using the globally injected
System.Net.Http.HttpClient instance provided in the application's Program.cs or Startup.cs.
Examples
@inject HttpClient httpClient
<SfUploader ID="UploadFiles" HttpClientInstance="@httpClient">
<UploaderAsyncSettings SaveUrl="api/SampleData/Save"
RemoveUrl="api/SampleData/Remove"/>
</SfUploader>
This example demonstrates setting the HttpClientInstance property to a globally injected
System.Net.Http.HttpClient instance, enabling shared HTTP configurations within the SfUploader component.
ID
Gets the ID of the Uploader component.
Declaration
public string ID { get; set; }
Property Value
| Type | Description |
|---|---|
| System.String | Accepts the string value. |
InputAttributes
Gets or sets an additional input attributes such as disabled, value, and more to add the input file element.
Declaration
public Dictionary<string, object> InputAttributes { get; set; }
Property Value
| Type | Description |
|---|---|
| System.Collections.Generic.Dictionary<System.String, System.Object> | A dictionary of additional input attributes for the root element of the component. |
Remarks
If you configured both property and equivalent input attribute, the component considers the property value.
MaxFileSize
Gets or sets the maximum allowed file size to be uploaded in bytes.
Declaration
public double MaxFileSize { get; set; }
Property Value
| Type | Description |
|---|---|
| System.Double | Accepts the double value representing that the maximum file size for the component. The default value is |
Remarks
The property used to make sure that you cannot upload too large files.
MinFileSize
Gets or sets the minimum file size to be uploaded in bytes.
Declaration
public double MinFileSize { get; set; }
Property Value
| Type | Description |
|---|---|
| System.Double | A double value representing the minimum file size for the component. The default value is |
OnActionComplete
Gets or sets the event callback that will be invoked after all selected files have been processed for upload, whether they completed successfully or failed during the upload operation to the server.
Declaration
public EventCallback<ActionCompleteEventArgs> OnActionComplete { get; set; }
Property Value
| Type | Description |
|---|---|
| Microsoft.AspNetCore.Components.EventCallback<ActionCompleteEventArgs> | An Microsoft.AspNetCore.Components.EventCallback<> that handles the action complete event. |
OnCancel
Gets or sets the event callback that will be invoked when a chunk file upload operation is canceled by the user. This event is only applicable when chunk uploading is enabled.
Declaration
public EventCallback<CancelEventArgs> OnCancel { get; set; }
Property Value
| Type | Description |
|---|---|
| Microsoft.AspNetCore.Components.EventCallback<CancelEventArgs> | An Microsoft.AspNetCore.Components.EventCallback<> that handles the upload cancellation event. |
OnChunkFailure
Gets or sets the event callback that will be invoked when a chunk file fails to upload to the server. This event provides error information for debugging upload failures in chunk upload scenarios.
Declaration
public EventCallback<FailureEventArgs> OnChunkFailure { get; set; }
Property Value
| Type | Description |
|---|---|
| Microsoft.AspNetCore.Components.EventCallback<FailureEventArgs> | An Microsoft.AspNetCore.Components.EventCallback<> that handles chunk upload failure events. |
OnChunkSuccess
Gets or sets the event callback that will be invoked when each chunk file is uploaded successfully to the server. This event is triggered for each successful chunk upload operation.
Declaration
public EventCallback<SuccessEventArgs> OnChunkSuccess { get; set; }
Property Value
| Type | Description |
|---|---|
| Microsoft.AspNetCore.Components.EventCallback<SuccessEventArgs> | An Microsoft.AspNetCore.Components.EventCallback<> that handles chunk upload success events. |
OnChunkUploadStart
Gets or sets the event callback that will be invoked when every chunk upload process gets started.
Declaration
public EventCallback<UploadingEventArgs> OnChunkUploadStart { get; set; }
Property Value
| Type | Description |
|---|---|
| Microsoft.AspNetCore.Components.EventCallback<UploadingEventArgs> | An Microsoft.AspNetCore.Components.EventCallback<> that handles the chunk upload start event. |
Remarks
Pass the additional data with the file uploading request in the CustomFormData argument.
Examples
@using Syncfusion.Blazor.Inputs
<SfUploader ID="UploadFiles" OnChunkUploadStart="@ChunkUploadStartHandler">
<UploaderAsyncSettings SaveUrl="api/SampleData/Save" RemoveUrl="api/SampleData/Remove" ChunkSize="50000" />
</SfUploader>
@code {
public void ChunkUploadStartHandler(UploadingEventArgs args) {
var accessToken = "Authorization_token";
args.CurrentRequest = new List<object> { new { Authorization = accessToken } };
}
}
OnClear
Gets or sets the event callback that will be invoked before clearing all items in the file list using the Clear button. This event allows you to cancel the clear operation or perform custom actions before clearing the file list.
Declaration
public EventCallback<ClearingEventArgs> OnClear { get; set; }
Property Value
| Type | Description |
|---|---|
| Microsoft.AspNetCore.Components.EventCallback<ClearingEventArgs> | An Microsoft.AspNetCore.Components.EventCallback<> that handles the file list clearing event. |
OnFailure
Gets or sets the event callback that will be invoked when a file upload or file removal request fails. This event provides error information to help diagnose and handle upload or removal failures.
Declaration
public EventCallback<FailureEventArgs> OnFailure { get; set; }
Property Value
| Type | Description |
|---|---|
| Microsoft.AspNetCore.Components.EventCallback<FailureEventArgs> | An Microsoft.AspNetCore.Components.EventCallback<> that handles upload or removal failure events. |
OnFileListRender
Gets or sets the event callback that will be invoked before rendering each file item in the file list. This event allows you to customize the structure and appearance of individual file items.
Declaration
public EventCallback<FileListRenderingEventArgs> OnFileListRender { get; set; }
Property Value
| Type | Description |
|---|---|
| Microsoft.AspNetCore.Components.EventCallback<FileListRenderingEventArgs> | An Microsoft.AspNetCore.Components.EventCallback<> that handles file list rendering events. |
OnRemove
Gets or sets the event callback that will be invoked when removing an uploaded file from the server. This event allows you to perform custom actions or confirmations before file removal.
Declaration
public EventCallback<RemovingEventArgs> OnRemove { get; set; }
Property Value
| Type | Description |
|---|---|
| Microsoft.AspNetCore.Components.EventCallback<RemovingEventArgs> | An Microsoft.AspNetCore.Components.EventCallback<> that handles file removal events. |
Remarks
This event can be used to confirm the file removal operation before it proceeds.
OnResume
Gets or sets the event callback that will be invoked when a paused chunk file upload is resumed. This event is only applicable when chunk uploading is enabled and provides pause/resume functionality.
Declaration
public EventCallback<PauseResumeEventArgs> OnResume { get; set; }
Property Value
| Type | Description |
|---|---|
| Microsoft.AspNetCore.Components.EventCallback<PauseResumeEventArgs> | An Microsoft.AspNetCore.Components.EventCallback<> that handles upload resume events. |
OnUploadStart
Gets or sets the event callback that will be invoked when the file upload process starts. This event allows you to add custom parameters to the upload request or perform pre-upload operations.
Declaration
public EventCallback<UploadingEventArgs> OnUploadStart { get; set; }
Property Value
| Type | Description |
|---|---|
| Microsoft.AspNetCore.Components.EventCallback<UploadingEventArgs> | An Microsoft.AspNetCore.Components.EventCallback<> that handles upload start events. |
OnValueChange
Gets or sets the event callback that will be invoked when the collection of the selected files is uploaded for each file.
Declaration
public EventCallback<UploadChangeEventArgs> OnValueChange { get; set; }
Property Value
| Type | Description |
|---|---|
| Microsoft.AspNetCore.Components.EventCallback<UploadChangeEventArgs> | An Microsoft.AspNetCore.Components.EventCallback<> that handles the file upload change event. |
Remarks
This event is triggered when the user selects a new file in the input file element.
To read the contents of the uploaded file, call the OpenReadStream() method of the IBrowserFile interface,
which returns a stream that you can use to read the file data.
Examples
@using Syncfusion.Blazor.Inputs
<SfUploader AutoUpload="true" ValueChange="@OnChange">
</SfUploader>
@code{
private async Task OnChange(UploadChangeEventArgs args)
{
try
{
foreach (var file in args.Files)
{
var path = @"D:\" + file.FileInfo.Name;
FileStream filestream = new FileStream(path, FileMode.Create, FileAccess.Write);
await file.File.OpenReadStream(long.MaxValue).CopyToAsync(filestream);
filestream.Close();
}
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
}
}
Paused
Gets or sets the event callback that will be invoked when a chunk file upload operation is paused by the user. This event is only applicable when chunk uploading is enabled and provides pause/resume functionality.
Declaration
public EventCallback<PauseResumeEventArgs> Paused { get; set; }
Property Value
| Type | Description |
|---|---|
| Microsoft.AspNetCore.Components.EventCallback<PauseResumeEventArgs> | An Microsoft.AspNetCore.Components.EventCallback<> that handles upload pause events. |
Progressing
Gets or sets the event callback that will be invoked during the file upload process to track upload progress. This event provides real-time information about the upload progress for each file.
Declaration
public EventCallback<ProgressEventArgs> Progressing { get; set; }
Property Value
| Type | Description |
|---|---|
| Microsoft.AspNetCore.Components.EventCallback<ProgressEventArgs> | An Microsoft.AspNetCore.Components.EventCallback<> that handles upload progress events. |
SequentialUpload
Gets or sets a value that indicates whether the SfUploader component processes multiple files sequentially rather than simultaneously.
Declaration
public bool SequentialUpload { get; set; }
Property Value
| Type | Description |
|---|---|
| System.Boolean |
|
Remarks
When the SequentialUpload property is enabled, the file upload component uploads files one after another instead of simultaneously.
ShowFileList
Gets or sets a value that indicates whether the file list should be rendered.
Declaration
public bool ShowFileList { get; set; }
Property Value
| Type | Description |
|---|---|
| System.Boolean |
|
Remarks
This property is used to hide the default file list and design your own template for the file list using the Template property.
ShowProgressBar
Gets or sets a value indicating whether to show the progress bar while uploading a file.
Declaration
public bool ShowProgressBar { get; set; }
Property Value
| Type | Description |
|---|---|
| System.Boolean |
|
Examples
@using Syncfusion.Blazor.Inputs
<SfUploader ID="UploadFiles" ShowProgressBar="false">
<UploaderAsyncSettings SaveUrl="api/SampleData/Save" RemoveUrl="api/SampleData/Remove" />
</SfUploader>
Success
Gets or sets the event callback that will be invoked when file upload or file removal operations complete successfully. This event provides confirmation and result information for successful operations.
Declaration
public EventCallback<SuccessEventArgs> Success { get; set; }
Property Value
| Type | Description |
|---|---|
| Microsoft.AspNetCore.Components.EventCallback<SuccessEventArgs> | An Microsoft.AspNetCore.Components.EventCallback<> that handles successful upload or removal events. |
TabIndex
Gets or sets the tab order of the component.
Declaration
public int TabIndex { get; set; }
Property Value
| Type | Description |
|---|---|
| System.Int32 | An integer value representing the tab index of the Uploader component. The default value is |
Template
Gets or sets a template that is used to customize the content of each file in the list.
Declaration
public RenderFragment<FileInfo> Template { get; set; }
Property Value
| Type | Description |
|---|---|
| Microsoft.AspNetCore.Components.RenderFragment<FileInfo> | The template content. The default value is |
Examples
@using Syncfusion.Blazor.Inputs
@inject HttpClient Http
<SfUploader ID="UploadFiles" DropEffect="DropEffect.Copy">
<UploaderAsyncSettings SaveUrl="api/SampleData/Save" RemoveUrl="api/SampleData/Remove"/>
<UploaderTemplates>
<Template Context="HttpContext">
<div style="padding: 7px;">
<h5 title="@(HttpContext.Name)">@(HttpContext.Name)</h5>
<i>@(HttpContext.Size) Bytes</i>
</div>
</Template>
</UploaderTemplates>
</SfUploader>
Methods
BuildRenderTree(RenderTreeBuilder)
Declaration
protected override void BuildRenderTree(RenderTreeBuilder __builder)
Parameters
| Type | Name | Description |
|---|---|---|
| Microsoft.AspNetCore.Components.Rendering.RenderTreeBuilder | __builder |
BytesToSizeAsync(Double)
Converts bytes value into kilobytes or megabytes depending on the size based on binary prefix.
Declaration
public Task<string> BytesToSizeAsync(double bytes)
Parameters
| Type | Name | Description |
|---|---|---|
| System.Double | bytes | The file size in bytes to be converted. |
Returns
| Type | Description |
|---|---|
| System.Threading.Tasks.Task<System.String> | A System.Threading.Tasks.Task<> that represents the asynchronous operation. The task result contains a System.String representing the formatted file size with appropriate units (B, KB, MB, GB, etc.). |
Remarks
This method converts numeric byte values to human-readable file size representations using binary prefixes (1024-based calculation). For example, 1024 bytes will be converted to "1 KB", and 1048576 bytes will be converted to "1 MB". The conversion follows the binary prefix standard where each unit is 1024 times larger than the previous unit.
Examples
Convert file size from bytes to readable format:
string fileSize = await uploaderInstance.BytesToSizeAsync(2048);
// Returns "2 KB"
CancelAsync(FileInfo[])
Stops the in-progress chunked upload based on the specified file data.
Declaration
public Task CancelAsync(FileInfo[] fileData = null)
Parameters
| Type | Name | Description |
|---|---|---|
| FileInfo[] | fileData | An array of Syncfusion.Blazor.Toolkit.Inputs.SfUploader.FileInfo objects representing the files to cancel. If |
Returns
| Type | Description |
|---|---|
| System.Threading.Tasks.Task | A System.Threading.Tasks.Task that represents the asynchronous cancel operation. |
Remarks
When the file upload is canceled using this method, the partially uploaded file chunks are automatically removed from the server. This method is particularly useful for chunked uploads where large files are divided into smaller parts for transmission. If no specific file data is provided, all currently uploading files will be canceled.
Examples
Cancel specific files or all uploads:
// Cancel specific files
await uploaderInstance.CancelAsync(selectedFiles);
// Cancel all uploads
await uploaderInstance.CancelAsync();
ClearAllAsync()
Clears all file entries from the upload list, including both uploaded files and files in the upload queue.
Declaration
public Task ClearAllAsync()
Returns
| Type | Description |
|---|---|
| System.Threading.Tasks.Task | A System.Threading.Tasks.Task that represents the asynchronous clear operation. |
Remarks
This method removes all files from the uploader component, whether they are already uploaded, currently uploading, or waiting in the queue. The method behavior varies based on whether the uploader is configured with server-side processing (SaveUrl) or client-side only processing. For server-side uploads, it communicates with the server to clear files, while for client-side only uploads, it clears the local file list.
Examples
Clear all files from the uploader:
await uploaderInstance.ClearAllAsync();
GetFileDetailsAsync(List<FileInfo>)
Retrieves and processes detailed information for the specified files. This method is invoked from JavaScript interop.
Declaration
public Task GetFileDetailsAsync(List<FileInfo> file)
Parameters
| Type | Name | Description |
|---|---|---|
| System.Collections.Generic.List<FileInfo> | file | A System.Collections.Generic.List<> of Syncfusion.Blazor.Toolkit.Inputs.SfUploader.FileInfo objects containing the files for which details need to be retrieved. |
Returns
| Type | Description |
|---|---|
| System.Threading.Tasks.Task | A System.Threading.Tasks.Task that represents the asynchronous file details retrieval operation. |
GetFilesDataAsync(Nullable<Double>)
Retrieves the data of files that are displayed in the file list.
Declaration
public Task<List<FileInfo>> GetFilesDataAsync(Nullable<double> index = null)
Parameters
| Type | Name | Description |
|---|---|---|
| System.Nullable<System.Double> | index | The optional index of a specific file to retrieve. If |
Returns
| Type | Description |
|---|---|
| System.Threading.Tasks.Task<System.Collections.Generic.List<FileInfo>> | A System.Threading.Tasks.Task<> that represents the asynchronous operation. The task result contains a System.Collections.Generic.List<> of Syncfusion.Blazor.Toolkit.Inputs.SfUploader.FileInfo objects representing the file data. |
Remarks
This method returns information about files currently displayed in the uploader's file list. If an index is specified, only the file at that position is returned (wrapped in a list). If no index is provided, all files in the current file list are returned. The behavior differs between server-side and client-side configurations, with server-side calls communicating with JavaScript interop.
Examples
Get all files or a specific file by index:
// Get all files
List<FileInfo> allFiles = await uploaderInstance.GetFilesDataAsync();
// Get specific file by index
List<FileInfo> specificFile = await uploaderInstance.GetFilesDataAsync(0);
PauseAsync(List<FileInfo>, Nullable<Boolean>)
Pauses the in-progress chunked upload based on the specified file data.
Declaration
public Task PauseAsync(List<FileInfo> fileData = null, Nullable<bool> custom = null)
Parameters
| Type | Name | Description |
|---|---|---|
| System.Collections.Generic.List<FileInfo> | fileData | A System.Collections.Generic.List<> of Syncfusion.Blazor.Toolkit.Inputs.SfUploader.FileInfo objects representing the files to pause. If |
| System.Nullable<System.Boolean> | custom | A System.Boolean value indicating whether custom UI is being used. Set to |
Returns
| Type | Description |
|---|---|
| System.Threading.Tasks.Task | A System.Threading.Tasks.Task that represents the asynchronous pause operation. |
Remarks
This method temporarily halts the upload process for chunked file uploads, allowing them to be resumed later using ResumeAsync(FileInfo[], Nullable<Boolean>). Pausing is particularly useful for large file uploads where users might want to temporarily stop the upload process due to network conditions or other priorities. The paused uploads maintain their current progress and can be resumed from the same point without losing uploaded chunks.
Examples
Pause specific files or all uploads:
// Pause specific files
await uploaderInstance.PauseAsync(selectedFiles);
// Pause all uploads
await uploaderInstance.PauseAsync();
RemoveAsync(FileInfo[], Nullable<Boolean>, Nullable<Boolean>, Nullable<Boolean>, Object)
Removes the uploaded files from the server manually by calling the remove URL action.
Declaration
public Task RemoveAsync(FileInfo[] fileData = null, Nullable<bool> customTemplate = null, Nullable<bool> removeDirectly = null, Nullable<bool> postRawFile = null, object args = null)
Parameters
| Type | Name | Description |
|---|---|---|
| FileInfo[] | fileData | An array of Syncfusion.Blazor.Toolkit.Inputs.SfUploader.FileInfo objects representing the files to remove from the file list and server. If |
| System.Nullable<System.Boolean> | customTemplate | A System.Boolean value indicating whether the component is rendering with a custom template. Set to |
| System.Nullable<System.Boolean> | removeDirectly | A System.Boolean value indicating whether to remove files directly without triggering removing events. Set to |
| System.Nullable<System.Boolean> | postRawFile | A System.Boolean value indicating the data format to post to the remove action. Set to |
| System.Object | args | Additional arguments to pass to the remove action. |
Returns
| Type | Description |
|---|---|
| System.Threading.Tasks.Task | A System.Threading.Tasks.Task that represents the asynchronous remove operation. |
Remarks
This method removes files both from the client-side file list and from the server storage by calling the configured remove URL. If no specific file data is provided, all files in the current list will be removed. The method behavior varies based on whether server-side processing is configured through the SaveUrl property. For client-side only configurations, files are removed from the local file collection without server communication.
Examples
Remove specific files or clear all files:
// Remove specific files
await uploaderInstance.RemoveAsync(selectedFiles);
// Clear all files
await uploaderInstance.RemoveAsync();
// Remove files with custom options
await uploaderInstance.RemoveAsync(selectedFiles, customTemplate: true, removeDirectly: false);
ResumeAsync(FileInfo[], Nullable<Boolean>)
Resumes the chunked upload that was previously paused based on the specified file data.
Declaration
public Task ResumeAsync(FileInfo[] fileData = null, Nullable<bool> custom = null)
Parameters
| Type | Name | Description |
|---|---|---|
| FileInfo[] | fileData | An array of Syncfusion.Blazor.Toolkit.Inputs.SfUploader.FileInfo objects representing the files to resume. If |
| System.Nullable<System.Boolean> | custom | A System.Boolean value indicating whether custom UI is being used. Set to |
Returns
| Type | Description |
|---|---|
| System.Threading.Tasks.Task | A System.Threading.Tasks.Task that represents the asynchronous resume operation. |
Remarks
This method continues the upload process for files that were previously paused using PauseAsync(List<FileInfo>, Nullable<Boolean>). The upload resumes from the exact point where it was paused, utilizing the already uploaded chunks without re-uploading them. This feature is particularly useful for handling large file uploads where network interruptions or user preferences require temporary pausing.
Examples
Resume specific paused files or all paused uploads:
// Resume specific files
await uploaderInstance.ResumeAsync(pausedFiles);
// Resume all paused uploads
await uploaderInstance.ResumeAsync();
RetryAsync(FileInfo[], Nullable<Boolean>, Nullable<Boolean>)
Retries the canceled or failed file upload based on the specified file data.
Declaration
public Task RetryAsync(FileInfo[] fileData = null, Nullable<bool> fromcanceledStage = null, Nullable<bool> custom = null)
Parameters
| Type | Name | Description |
|---|---|---|
| FileInfo[] | fileData | An array of Syncfusion.Blazor.Toolkit.Inputs.SfUploader.FileInfo objects representing the files to retry. If |
| System.Nullable<System.Boolean> | fromcanceledStage | A System.Boolean value indicating the retry starting point. Set to |
| System.Nullable<System.Boolean> | custom | A System.Boolean value indicating whether custom UI is being used. Set to |
Returns
| Type | Description |
|---|---|
| System.Threading.Tasks.Task | A System.Threading.Tasks.Task that represents the asynchronous retry operation. |
Remarks
This method allows users to restart uploads for files that have failed or been canceled during the upload process. When retrying from the canceled stage, the upload continues from where it was interrupted, preserving any successfully uploaded chunks. When retrying from the initial stage, the entire upload process starts over from the beginning. This functionality is essential for handling network issues, server timeouts, or user-initiated cancellations.
Examples
Retry failed uploads with different options:
// Retry specific files from canceled stage
await uploaderInstance.RetryAsync(failedFiles, fromcanceledStage: true);
// Retry all failed files from initial stage
await uploaderInstance.RetryAsync(fromcanceledStage: false);
SortFileListAsync(FileInfo[])
Sorts the file data alphabetically based on the file names.
Declaration
public Task<List<FileInfo>> SortFileListAsync(FileInfo[] filesData = null)
Parameters
| Type | Name | Description |
|---|---|---|
| FileInfo[] | filesData | An array of Syncfusion.Blazor.Toolkit.Inputs.SfUploader.FileInfo objects representing the files to sort. If |
Returns
| Type | Description |
|---|---|
| System.Threading.Tasks.Task<System.Collections.Generic.List<FileInfo>> | A System.Threading.Tasks.Task<> that represents the asynchronous operation. The task result contains a System.Collections.Generic.List<> of Syncfusion.Blazor.Toolkit.Inputs.SfUploader.FileInfo objects sorted alphabetically by file name. |
Remarks
This method organizes the file list in alphabetical order based on the file names, making it easier for users to locate specific files. The sorting is case-insensitive and follows standard alphabetical ordering rules. If no specific file data is provided, the method will sort all files currently present in the uploader's file list.
Examples
Sort files alphabetically:
// Sort specific files
List<FileInfo> sortedFiles = await uploaderInstance.SortFileListAsync(selectedFiles);
// Sort all files in the list
List<FileInfo> allSortedFiles = await uploaderInstance.SortFileListAsync();
UploadAsync(FileInfo[], Nullable<Boolean>)
Initiates the upload process manually by calling the save URL action.
Declaration
public Task UploadAsync(FileInfo[] files = null, Nullable<bool> custom = null)
Parameters
| Type | Name | Description |
|---|---|---|
| FileInfo[] | files | An array of Syncfusion.Blazor.Toolkit.Inputs.SfUploader.FileInfo objects representing the specific files to upload. If |
| System.Nullable<System.Boolean> | custom | A System.Boolean value indicating whether to use custom file handling. Set to |
Returns
| Type | Description |
|---|---|
| System.Threading.Tasks.Task | A System.Threading.Tasks.Task that represents the asynchronous upload operation. |
Remarks
This method manually triggers the upload process for files in the uploader component. If no specific files are provided, all files currently in the upload queue will be uploaded. The method behavior varies based on the uploader configuration: for server-side uploads, it communicates with the configured SaveUrl, while for client-side only scenarios, it processes files locally through the upload handler. This method is useful when you need programmatic control over when uploads should begin.
Examples
Upload files manually:
// Upload specific files
await uploaderInstance.UploadAsync(selectedFiles);
// Upload all queued files
await uploaderInstance.UploadAsync();
// Upload with custom handling
await uploaderInstance.UploadAsync(selectedFiles, custom: true);