Upload Widget is it possible to keep content when screen rendered?

Upload Widget is it possible to keep content when screen rendered?

Have a popup with a Upload widget but everytime i submit the content is cleared even if the action failed because it didnt pass some validation. is there any way of not losing the upload widget content?
Yes there is a way, but it requires a bit of work (and a rather lengthy explanation).  

The first thing is to understand that the traditional form validation happens client side before the form is submitted to the server.  This validation happens before the file stream is sent to the server.  It also so happens that typical browser based file upload components are intentionally designed (for security reasons) to reset its values when the form is re-rendered in the browser.  So if your form field validations fail, the form is rerendered to show the validation errors and you lose the upload values.

To get around this issue, you can turn off client side validation and implement all you form validations server side.  This apporach will require you to not only manually do all the validations for each form field, but also manually set or reset the validation status and message for each of the form fields.  

The upside of this approach is that the file stream is sent to the server before any of the validations happen, so you not only get a chance to keep the content, but you also have the opportunity of validating the file size, file type or any other aspect of the file stream you choose and treat an error as part of the form validation.

If your application for example requires a specific excel spreadsheet to be uploaded, you could not only verify that a spreadsheet was in fact uploaded, but you could also inspect the contect of the uploaded file to ensure that the correct file was uploaded.  

Hope this helps.