I have a simple HTML form that sends an selected file via AJAX to an API endpoint.
If I do the following steps:
A quick workaround would be to include a complete
parameter to AJAX call (or any equivalent of a finally
call that always gets invoked) and add code that resets the form. I've noticed that attaching the file again solves it. While I appreciate it's not a real solution to the problem, it does provide handling or rather avoidance of that error.
This way, if the user for any reason needs to re-upload the file, they'll have to choose the file again.
Example below:
$.ajax({
url: this.action,
type: this.method,
data: this.data,
success: function (response) {
// success scenario
},
error: function (result) {
// error scenario
},
complete: function (data) {
$('#uploadForm')[0].reset(); // this will reset the form fields
}
});