File-uploads in rails 2.0.2 + AJAX

hi,

I am porting an app from 1.2.5 to 2.0.2 and I am having problems with file
uploads. The form fields look like this:

<%= 'Add attachment'.t %>: <%= file_field 'attachments', "upload#{id}", :size => '40' %>

The old code expects params[:attachments]["upload#{i}"] to be an object (File?)
with a method "original_filename".
I am using ajax (and previously didn't):

  <% form_remote_tag(:url => url_for(:controller => :mex, :action => :submit_answer, :id => mex_exercise.id), :update => "answer_#{mex_exercise.id}", :html => {:multipart => mex_exercise.num_attachments_allowed > 0}) do %>

(num_attachments_allowed is > 0 and I see the enctype-attribute:
  <form action="/en/mex/submit_answer/46" enctype="multipart/form-data" method="post" onsubmit="new Ajax.Updater('answer_46', '/en/mex/submit_answer/46', {asynchronous:true, evalScripts:true, parameters:Form.serialize(this) + '&authenticity_token=' + encodeURIComponent('a5de291b429a9def0d4ff822d8e278172e472a28')}); return false;"><div style="margin: 0pt; padding: 0pt;">)

Do I need to change anything because of ajax?

thanks,

File uploads can't be done over ajax (because the javascript isn't allowed to read files from your computer). There are tricks you can play with iframes and so on.

Fred

Indeed as another poster has already mentioned you can’t upload files through ajax (javascript security).

Either use a Flash uploader like swfupload.org (but if you’re not fairly fluent in Javascript, i would advise against it), do know that the new session security measures cause problems if you want the upload to be authenticated or search for the responds_to_parent plugin and follow the instructions.

Best regards

Peter De Berdt

I also use v2.0.2 and have problem with remote file upload. I followed
the instructions from this page
http://khamsouk.souvanlasy.com/2007/5/1/ajax-file-uploads-in-rails-using-attachment_fu-and-responds_to_parent
and getting error
undefined method `content_type' in
vendor/plugins/attachment_fu/lib/technoweenie/attachment_fu.rb:260:in
`uploaded_data

anybody handled this problem in rails 2 ?

Marek