0

I'm trying to make a file upload form using the hidden iframe method. In other words, I have a form like so....

<form action="upload" target="uploadFrame" 
      method="post" enctype="multipart/form-data">
   <!--There are other hidden fields that i've omitted for the sake of brevity -->
   <input type="file" id="file" name="file" />
</form>

And then I have javascript function that calls sumbit() on that form.

I want the action "upload" to respond with an HTTP 200 OK containing some arbitrary status. I've found a few different methods for obtaining the content of an iframe from its parent document.

Where I'm finding this whole method to be problematic is coming up with a reliable means of detecting and handling error cases such as 1) browser failing to connect to server, 2) connection dropping while uploading the file, 3) server sending an error response that does not include an entity. In other words, the types of errors where a browser generated response will usually be displayed in the frame.

Any suggestions would be appreciated. But I'd really prefer to keep it pure javascript (i.e. no jQuery or other frameworks).

Brian McFarland
  • 9,052
  • 6
  • 38
  • 56

1 Answers1

0

I'd say you could start a timeout for an error message when you submit the form, and if your form target is on the same domain, make it return a tag with a call to a function that clears the timeout and informs you of the success

Orestes
  • 356
  • 1
  • 3
  • 12
  • That might be a workable solution, but it requires that I have a good idea what the network looks like to come up with a good timeout. It's for uploading fairly large files (maybe a couple MB) the time it takes to upload a file on a 100 MB LAN is substantially different from how long it takes over dialup. – Brian McFarland Dec 12 '11 at 16:10
  • The I think you should check out this other question http://stackoverflow.com/questions/164085/javascript-callback-when-iframe-is-finished-loading Reading that I thought you could use a setInterval checking when the iframe is ready. Taking it from there I'd check for the iframe content to know if there was a succesful upload. – Orestes Dec 16 '11 at 23:31