New to Telerik UI for Blazor? Start a free 30-day trial
Chunk Upload
Chunk upload works by splitting a file into smaller parts (chunks) and sending them in multiple requests. These chunks are then reassembled at the remote endpoint into the final file.
Basics
To set up the Chunk upload feature, use the UploadChunkSettings
tag, which is nested inside UploadSettings
. The tag includes the following parameters:
Parameter | Type and Default Value | Description |
---|---|---|
AutoRetryAfter | double (100) | Specifies the amount of time in milliseconds after which a failed chunk upload request will be retried. |
Enabled | bool ( true ) | Specifies if the chunk upload is enabled. |
MaxAutoRetries | int (1) | Specifies the number of attempts to retry uploading a failed chunk. |
MetadataField | string ( chunkMetadata ) | Specifies the name of the variable that will receive the chunk upload metadata in the remote endpoint. |
Resumable | bool ( true ) | Specifies if the file upload process can be paused and later resumed. |
Size | double (1024 * 1024) | The size of the chunks in bytes. |
Events
The Upload exposes several relevant events. You can find related examples in the Events article.
OnPause
—fires when the user clicks on the pause button during chunk upload.OnResume
—fires when the user clicks on the "resume" button during chunk upload.
Example
The UploadController
class below assumes that the project name and namespace is TelerikBlazorApp
.
Make sure to enable controller routing in the app startup file (Program.cs
). In this case, app.MapDefaultControllerRoute();
is all that's needed.
Also see:
- Section Implement Controller Methods
- Page Upload Troubleshooting
Enable Chunk Upload
RAZOR
<TelerikUpload SaveUrl="@CustomSaveUrl"
OnPause="@OnPause"
OnResume="@OnResume"
RemoveUrl="@RemoveUrl"
AutoUpload="true">
<UploadSettings>
<UploadChunkSettings Size="16000"
AutoRetryAfter="300"
MaxAutoRetries="2"
MetadataField="customChunkMetadata"
Resumable="false">
</UploadChunkSettings>
</UploadSettings>
</TelerikUpload>
@code {
private string SaveUrl => NavigationManager.ToAbsoluteUrl("api/upload/chunksave");
private string RemoveUrl => NavigationManager.ToAbsoluteUrl("api/upload/remove");
private string CustomSaveUrl => NavigationManager.ToAbsoluteUrl("api/upload/chunksavecustom");
private void OnPause(UploadPauseEventArgs args)
{
Console.WriteLine("pause event");
foreach (var file in args.Files)
{
Console.WriteLine(file.Name);
}
}
private void OnResume(UploadResumeEventArgs args)
{
Console.WriteLine("resume event");
foreach (var file in args.Files)
{
Console.WriteLine(file.Name);
}
}
}