Saturday, October 27, 2012

AJAX Style file uploads using an iFrame

I was recently trying to solve a strange issue with Internet Explorer 8 (it's always IE...) on redirecting the user after successfully uploading a file.  Couldn't use HTML5's FileUpload API as we had to be able to support older browsers but what we wanted was AJAX style in place uploads without having to redirect users back to the page after they had uploaded a file.

Then I came across the following blog post:
http://www.alfajango.com/blog/ajax-file-uploads-with-the-iframe-method/

This method feels like a bit of a hack but is a decent solution to the problem.  Target the empty iFrame and you can keep users on the same page.  It seems to be a popular method and one I'll use again until we can finally move to using the proper HTML5 API for doing this.