Unplanned
Last Updated: 13 Oct 2020 07:30 by ADMIN
SL
Created on: 13 May 2020 16:40
Category: Upload
Type: Bug Report
7
The Retry button does not fire OnUpload and you can't attach auth tokens
If a request fails once, the upload will give you a Retry button. This button does not fire OnUpload again, so the request no longer has the custom logic (such as bearer tokens).
1 comment
ADMIN
Marin Bratanov
Posted on: 13 Oct 2020 07:30

An idea for a workaround is to, perhaps, hide the Retry button altogether for the users, with a bit of CSS:

<style>
    .k-upload-status .k-upload-action:nth-of-type(2n+1) {
        display: none;
    }
</style>

@inject NavigationManager NavigationManager

<TelerikUpload SaveUrl="@SaveUrl"
               RemoveUrl="@RemoveUrl"
               OnUpload="@OnUploadHandler">
</TelerikUpload>

@code {
    async Task OnUploadHandler(UploadEventArgs e)
    {
        // a flag to make uploads error out, see the controller
        e.RequestData.Add("shouldFail", "true"); 
    }

    // a sample way of generating the URLs to the endpoint
    public string SaveUrl => ToAbsoluteUrl("api/upload/save");
    public string RemoveUrl => ToAbsoluteUrl("api/upload/remove");

    public string ToAbsoluteUrl(string url)
    {
        return $"{NavigationManager.BaseUri}{url}";
    }
}

and the controller just throws for that test case:

        [HttpPost]
        public async Task<IActionResult> Save(IEnumerable<IFormFile> files)
        {
            string shouldFail = Request.Form["shouldFail"]; // the key from the OnUpload event that will make the request fail
            if (shouldFail != null && shouldFail.ToLowerInvariant().Equals("true"))
            {
                Response.StatusCode = 401;
                return new EmptyResult();
            }

Regards,
Marin Bratanov
Progress Telerik

Five days of Blazor, Angular, React, and Xamarin experts live-coding on twitch.tv/CodeItLive, special prizes, and more, for FREE?! Register now for DevReach 2.0(20).