Hi,
Two questions. Or three. Several issues at once.
I'm using the YUI uploader with Rails, or at least I'm trying.. (http://developer.yahoo.com/yui/uploader/)
[ABOUT: The YUI uploader is a Flash-uploader, which is invisble on the page and is controlled by Javascript. It is used to asynchronously upload files from a webpage. Because it's Flash, it can produce reliable progress messages WITHOUT involving the server.]
I create a normal form using <%- form_for(@video, :html => { :multipart => true) do |f| -%>
In Javascript I fill an object with the contents of the created form fields. I also include _session_id as POST variable, because Flash has a bug and uses MS IE cookies even when run in side Firefox - so I can forget about using cookie based session for this file upload. However, this seems to fail (see below, log of webserver), the session info seems lost and therefore my auth.token question below may already be answered? But how DO I get the session established correctly if I don't have the session cookie available in this POST?
var postvars = { video: , authenticity_token: "<%= form_authenticity_token %>", _session_id: "" };
//...code to fill video with the form_for field input field contents... //like this: postvars.video["name"] = document.forms[1].elements["video[name]"].value;
uploaderSWF.uploadAll('/videos', "POST", postvars, "video[uploaded_data]");
This causes the uploader (or it should) to perform the exact same POST operation the form would generate in the web browser.
TWO ISSUES:
One, I get an error about a wrong authenticity token. How is this possible, since I'm including it? Okay, so I exempted the receiving method from forgery_protection for further testing. Two, I don't see the video array variables posted! Rails created <input name="video[name]"...> style form fields. I tried to recreate them using the above JS video array in postvars. I can't think of any other way, unfortunately. Okay, while writing this it dawns on me why this fails, for the browser this is just a string ("video[name]"), and if the Flash does not produce such strings when doing the POST...
SERVER LOG OF REQUEST
Processing VideosController#create (for 127.0.0.1 at 2008-05-14 13:32:01) [POST] Session ID: 2a721552e475206033975ece7a440b35 Parameters: {"Filename"=>"TXT", "_session_id"=>"BAh7CToMY3NyZl9pZCIlODRjODFkNjg1ZjBlNjFmNjY1MjVmMmUwZjUzNjA3%250AMmU6DnJldHVybl90bzA6DHVzZXJfaWRpAiYIIgpmbGFzaElDOidBY3Rpb25D %250Ab250cm9sbGVyOjpGbGFzaDo6Rmxhc2hIYXNoewAGOgpAdXNlZHsA--579a97d93618e59bddba08d758f93d0ae6c5b501", "authenticity_token"=>"a2061d419e4b3be9452fcb78cf4aeaa8ba02c17c", "action"=>"create", "Upload"=>"Submit Query", "controller"=>"videos", "YUIuploader"=>"1", "video"=>{"uploaded_data"=>#<ActionController::UploadedStringIO: 0xb69da3e4>}} Redirected to http://localhost:3000/session/new Filter chain halted as [#<ActionController::Filters::ClassMethods::SymbolFilter:0xb697d8ec @filter=:login_required>] rendered_or_redirected. Completed in 0.00063 (1599 reqs/sec) | DB: 0.00277 (443%) 0 queries | 302 Found [http://localhost/videos\]
Thanks! Michael