Class UploaderEvents
Represents a class that contains all the event callbacks for the SfUploader component. This class provides event handling capabilities for various upload operations including file selection, upload progress, success, failure, and file management operations.
Inheritance
Namespace: Syncfusion.Blazor.Inputs
Assembly: Syncfusion.Blazor.dll
Syntax
public class UploaderEvents : OwningComponentBase
Constructors
UploaderEvents()
Declaration
public UploaderEvents()
Properties
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>
<UploaderEvents 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. |
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. |
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">
<UploaderAsyncSettings SaveUrl="api/SampleData/Save" RemoveUrl="api/SampleData/Remove" ChunkSize="50000" />
<UploaderEvents OnChunkUploadStart="@ChunkUploadStartHandler" />
</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. |
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. |
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. |
ValueChange
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> ValueChange { 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">
<UploaderEvents ValueChange="@OnChange"></UploaderEvents>
</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);
}
}
}