Setting a limiting file size on RadzenUpload

Hi. First time here. Radzen looks very promising.I'm researching if Radzen is worthwhile to replace an old Telerik-based CMS and so far it's going well, except for an issue I bumped into today:

I implemented a RadzenUpload. Now, I want to set a limiting file size of e.g. 2MB for a PNG image. Telerik had a nice MaxFileSize parameter for that in their upload component and would throw an error for larger files. I was hoping for something similar, but no.

So, I decided to be creative: I assumed the Change event is called right after a file is selected and prior to the actual start of uploading the file to the server. I therefore thought i could get the (single) file via the UploadChangeEventArgs and then just use args.Files.First().Size to validate its size and if that was invalid, stop the upload process by just invoking the reffed _upload.Error.InvokeAsync();. However, the Change event is NEVER invoked when i pick a file? That must be a bug?

By default the upload will start immediately and the change event will not be raised. You can set Auto="false" similar to the Manual Upload example in our demo:
https://blazor.radzen.com/example-upload

Ah thanks for the help. That works and now my Change callback can indeed invalidates files that are too large.

So for those interested:

  1. set Auto="false" in the RadzenUpload :wink:
  2. write your file name/extension and file size validator method and hook that to the OnChange callback so you can check FileInfo for each file before it gets uploaded
  3. make sure you reffed the RadzenUpload so you can call _upload.Upload() when everything is valid
  4. use a custom method in your UploadController to further validate the file AFTER uploading (e.g. image dimensions) or to copy it to the definite folder you wan to store it, etc
  5. do a ClearFiles() in the Complete callback if you want the RadzenUpload to be clean slate again
    (also add that to the error handling btw)