BoldSignA modern eSignature application with affordable pricing. Sign up today for unlimited document usage!
I have the following properties set:
AllowedExtensions=".xlsx, .xls"
AllowMultiple=false
ShowFileList=false
MinFileSize="10000"
MaxFileSize="614400"
Since I'm hiding the file list, we don't get to see the messages when the file size or type is disallowed or if they tried to upload more than one file at once.
How can I trap for those so I can display my own error messages? I certainly don't want to just ignore the upload without giving the user some feedback. But I also don't need or want the file list.
On further research, I found this:
void OnBeforeUpload(BeforeUploadEventArgs args)
{
Console.WriteLine(args.FilesData[0]...)
}
Does BeforeUpload actually trigger before the file is sent to the server? If you don't provide a way for us to show status messages when min/max or file type or multiple files is attempted, then maybe I turn those restrictions off and put them in BeforeUpload? Then I can do my own checks and messages.
Let
You can use the FileSelected event to know the file upload restricted message, such as file type and file size. To indicate to the user whether the file was uploaded successfully or not, you can use the Success and OnFailure events.
Please refer to the code snippet and sample below for more information.
<div style="margin:130px auto;width:300px"> @if (ErrorMessage != null && ErrorMessage != "Ready to upload") { <p>@ErrorMessage</p> }
<SfUploader AllowedExtensions=".xlsx, .xls" AllowMultiple=false ShowFileList=false MinFileSize="10000" MaxFileSize="614400"> <UploaderEvents FileSelected="@FileSelectedHandler" OnFailure="@OnFailureHandler" Success="@SuccessHandler"></UploaderEvents> </SfUploader> </div> @code { private string ErrorMessage; private void FileSelectedHandler(SelectedEventArgs args) { if (args.FilesData.Count != 0) { ErrorMessage = args.FilesData[0].Status; }
} private void OnFailureHandler(FailureEventArgs args) { ErrorMessage = args.File.Status; } private void SuccessHandler(SuccessEventArgs args) { ErrorMessage = args.File.Status; } } |
All three functions update the ErrorMessage variable, which is then used to display any error messages in the code block inside the if statement in the HTML code. If there are no errors, the ErrorMessage variable will be set to "Ready to upload", which will not be displayed.
|