Unplanned
Last Updated: 22 Apr 2024 10:21 by Quentin
Quentin
Created on: 22 Apr 2024 10:21
Category: Upload
Type: Feature Request
3
Call the RemoveUrl endpoint for removing Initial Files

When the Upload has Initial Files, the RemoveUrl endpoint is not called when the user removes them from the UI. 

===

TELERIK EDIT

The current workaround is to call the RemoveUrl in the Upload's OnRemove event handler. This is also applicable when you need to send additional custom data with the file name.

.razor file

@inject HttpClient HttpClient

<TelerikUpload OnRemove="@OnUploadRemove" RemoveUrl="@RemoveUrl" />

@code {
    private string RemoveUrl { get; set; } = "api/upload/remove";

    private async Task OnUploadRemove(UploadEventArgs args)
    {
        // code for non-initial files
        // send optional custom data to the controller
        args.RequestData.Add("requestKey", "custom value");

        // code for initial files
        // call the RemoveUrl
        if (args.Files.First().Status == UploadFileStatus.Blank)
        {
            var multipartContent = new MultipartFormDataContent();

            multipartContent.Add(new StringContent(args.Files.First().Name), "files"); // "files" must match the RemoveField value
            multipartContent.Add(new StringContent("requestKey"), "custom value"); // send optional custom data to the controller

            await HttpClient.PostAsync(RemoveUrl, multipartContent);
        }
    }
}

 

Program.cs

builder.Services.AddHttpClient();

 

0 comments