Upload Error on v4.0

  • Unexpected JSON token False. Ensure that the call to `RadzenUpload.OnProgress' is supplied with exactly '4' parameters.

  • Unexpected JSON token False. Ensure that the call to `RadzenUpload.OnComplete' is supplied with exactly '1' parameters.

///CODE
<RadzenUpload Url=@($"upload/file/{fileName}") Progress=@TrackProgress Complete=@CompleteUpload class="w-100" />

<RadzenButton Text="Cancel" Click=@(args => CancelUpload()) class="d-block mt-4" Visible=@showProgress />

@code {
RadzenUpload upload;
[Parameter]
public string fileName { get; set; }
[Parameter]
public string filePath { get; set; }
[Parameter]
public EventCallback filePathChanged { get; set; }

int progress;
bool showProgress;
bool showComplete;
string completionMessage;
bool cancelUpload = false;
void TrackProgress(UploadProgressArgs args)
{
    showProgress = true;
    showComplete = false;
    progress = args.Progress;
}
async void CompleteUpload(UploadCompleteEventArgs args)
{
    completionMessage = "Upload Complete!";
    showProgress = false;
    showComplete = true;
    filePath = args.RawResponse;
    await filePathChanged.InvokeAsync(filePath);
}
void CancelUpload()
{
    cancelUpload = true;
}
void OnProgress(UploadProgressArgs args, string name)
{
    Console.WriteLine("{args.Progress}% '{name}' / {args.Loaded} of {args.Total} bytes.");

    if (args.Progress == 100)
    {
        foreach (var file in args.Files)
        {
            Console.WriteLine("Uploaded: {file.Name} / {file.Size} bytes");
        }
    }
}
async void OnComplete(UploadCompleteEventArgs args)
{
    filePath = args.RawResponse;
    await filePathChanged.InvokeAsync();
}

}
///CODE

We will need more information about the problem. Our online demo seems to work as expected and all the events fire as advertised.

Why is this error popping sir. the api controller is getting hit but both the complete event and progress event are not firing in client side.

It seems the returned response isn't valid JSON.

[HttpPost("file")]
public IActionResult Image(IFormFile file)
{
try
{
var fileName = $"{file.FileName.ToString().Split(".")[0]}-{DateTime.Today.ToString("yyyy-MM-dd")}{Path.GetExtension(file.FileName)}";
using (var stream = new FileStream(Path.Combine(_environment.WebRootPath, fileName), FileMode.Create))
{
file.CopyTo(stream);
var url = Url.Content($"~/{fileName}");
return Ok(url);
}
}
catch (Exception ex)
{
return StatusCode(500, ex.Message);
}
}
**In URL string im getting my desired result **

I am afraid I can't determine the cause of the problem from the provided code and information so far. Are you positive the problem started to happen after upgrading to Radzen.Blazor 4.0? It doesn't have any upload related changes. Does downgrading resolve the issue?

do i need to provide with any specific info or codes so you might be able to determine the issue

You didn't answer my questions ...

i haven't tried let me check sir,