Upload a file from dialog box

Upload a file from dialog box

I have a form to upload a file + some meta data about the file (description, caption, alt tag, etc).  I am displaying this form inside a modal jquery dialog box, and I want the result of the form submission to display inside the dialog.  This workflow works fine with other forms without file uploads, however, with the file upload, if there are server side errors on the form (IE duplicate file name, file too large) the return from the form submission is html of the form with error messages.  This breaks with file uploads (I assume because it doesn't actually write to the dialog but to the hidden iframe).

The problem is that after an error submission, the form displays appropriately, but I can't make the form an ajax form again (cause I don't know where it is? or because inside the iframe jquery+jquery forms is not available?) I've tried adding jquery and jquery forms to the html that is returned if there is an error on the form, but this does not work (possibly because inside the iframe it can't find the "target" which is the dialog box id?)  Anyway... point is after an error submission, if I repost the form, it now doesn't keep the return info (success or failure) inside the dialog box, but takes over the entire page.

any idea on how to solve this issue?  Or a different workflow that will work?