Florian Müller Florian Müller - 1 year ago 192
Ajax Question

Bootstrap Fileinput does not send file again on second upload

When I upload a file with Krajees Bootstrap Fileinput, I perform a server side validation of the file. When something goes wrong, I output a JSON-Object simply with

{error:'Something went wrong'}
. The Plugin displays the error perfectly.

But then: When I press again "upload" just after that, the
array in the called submit PHP script is empty. This means, the plugin does not send the file again even if it has notified that an error has occurred.

Why would the plugin only upload the file once even if it detects that there was an error? Are there any methods that can "reset" the "uploaded state" of the file? (I'm only uploading one file).

I already checked the file events but none of them brought me to the desired result, instead they kind of destroyed the whole upload form with certain buttons being suddenly disabled and so on.

Answer Source

I finally found out the exact point, where the problem could be solved:

On line 1705 in the function updateUploadLog, the function self.updateStack is called. This call simply clears the file stack and causes a later process to empty the form input. Simply commenting out would cause the stack not to be cleared even on success, so I added a parameter isError, because the function only gets called in fnSuccess and fnError, making it simple to separate. And BOOOM there goes the solution!

@Angad thank you very much for your solution triggering input, thanks to that I found a place to start the search again ;)

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download