-
-
Notifications
You must be signed in to change notification settings - Fork 2.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fileuploaderror - return custom error message. #1779
Comments
To show a custom error message its recommended if you catch all exceptions in your server UPLOAD code and return the right validation error message via the server. For example the server code in your The above is the most optimal method IMO... but do check and let know. The |
I am currently using JSON key error in my server catch statements and it works for most use cases. I agree this is the best approach to display server errors. However, this use case is different as the error happens due to server memory issues. This is a fatal error, which I can catch in PHP register_shutdown_function, but I cannot be sure at that point what exactly caused memory issues. In short, in this case I am not able to return error key with JSON. At least I don't think I can (maybe I am wrong). As a result, user sees an ugly error message which reveals more than error message should reveal. So, I want to change it on the client end within the fileuploaderror event. Perhaps there is a way to enable just to change the error message within fileuploaderror without aborting and locking the input (as you described above). |
Noting a possible enhancement to see if there is a way to trigger a custom message for such cases. |
There is a new enhancement added to achieve these scenarios and a new plugin method To show your own custom user error - you can use the following enhanced method var $input = $('#file-input-id');
$input.on('fileuploaderror', function(event, data) {
var userMessage = 'We could not process the upload because of a server error.';
// to show error specific to each file pass the data as received above - pass `data` (the data object must contain the `fileId`)
$input.fileinput('showUserError', userMessage, data);
// to show a constant global error not specific to each file do not pass `data` (uncomment below line to achieve this)
// $input.fileinput('showUserError', userMessage);
}); |
Thank you for the fix! Below is the code I use and here is the screenshot of the output. I was uploading 3 files and got 1 error, which is displayed as a custom error message. There is no file specific data (such as filename) in the error. Data contains the fileId property.
|
Prerequisites
master
branch of bootstrap-fileinput.Steps to reproduce the issue
return { message: 'You are not allowed to do that'}.
Expected behavior and actual behavior
Please see this screenshot. I can get the error displayed in message parameter of the fileuploaderror. Is there any elegant way to change it and display a more user friendly error? As a last resort I can go and change the html with Java Script, but it is messy. Perhaps I did not find in the documentation something similar to return { message: 'error to display to the user'}?
Environment
Browsers
Operating System
Libraries
Isolating the problem
The text was updated successfully, but these errors were encountered: