New to Telerik UI for BlazorStart 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:

ParameterType and Default ValueDescription
AutoRetryAfterdouble
(100)
Specifies the amount of time in milliseconds after which a failed chunk upload request will be retried.
Enabledbool
(true)
Specifies if the chunk upload is enabled.
MaxAutoRetriesint
(1)
Specifies the number of attempts to retry uploading a failed chunk.
MetadataFieldstring
(chunkMetadata)
Specifies the name of the variable that will receive the chunk upload metadata in the remote endpoint.
Resumablebool
(true)
Specifies if the file upload process can be paused and later resumed.
Sizedouble
(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:

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);
        }
    }
}

See Also

In this article
BasicsEventsExampleSee Also
Not finding the help you need?
Contact Support