File upload with form_remote_tag

Is there a way to use form_remote_tag and to upload a file? The default
behavior ignores the upload when the Javascript serializes the form to
create the parameter list.

Basically, i’m just looking for an ajax file upload capability. Any help
would be appreciated.

thanks.

On 8/6/06, Larry W. [email protected] wrote:

Is there a way to use form_remote_tag and to upload a file? The default
behavior ignores the upload when the Javascript serializes the form to
create the parameter list.

Basically, i’m just looking for an ajax file upload capability. Any help
would be appreciated.

Not possible - the javascript security model prevents it

http://mir.aculo.us/articles/2005/09/30/fud-revisited-1-can-you-upload-files-with-ajax
has a good explanation of the issues. Here’s the list of steps I went
through to get a simple file upload that refreshed a list of uploaded
files via an ajax call when done:

  1. Make an iframe to hold the file upload form
  2. Include prototype.js in both the upload page and the main page
  3. In the iframe, have

<%= start_form_tag(
{:action => ‘create’ },
{:multipart => true,
:onSubmit => “setTimeout(‘parent.refreshFileList()’, 1000)”
})%>

  1. In the main page, have

function refreshFileList()
{
new Ajax.Updater(‘fileListContainer’, ‘/resources/updatelist’,
{asynchronous: true});
return false;
}

martin

On Aug 6, 2006, at 2:36 AM, Martin DeMello wrote:

  1. In the iframe, have
    {
    new Ajax.Updater(‘fileListContainer’, ‘/resources/updatelist’,
    {asynchronous: true});
    return false;
    }

martin

I had to do this recently myself. I tried a bunch of different

options and the best way to get it done is with a plugin called
respond_to_parent that uses a hidden iframe as a target for the form
upload and lets you send rjs back to the iframe that then gets
eval’ed in the parent window.

http://sean.treadway.info/svn/plugins/responds_to_parent/README

-Ezra