problem with session

as my first project i am playing around with the swfupload ruby demo now i have run in a problem i dont get, maybe due to my lack of ror experience

what i want to do is, during upload, get the ids of the uploaded pics, put them in session[:new_photos] and then use this information in another view to tag all the newly uploaded pics

swfupload uploads the files to this, one file after another, so the swfupload method gets called multiple times for multiple files

def swfupload     # swfupload action set in routes.rb

    # The content_type is set as application/octet by the flash program     # Use mimetype-fu to determine the mimetype before passing it     # to the attachment_fu enabled model     session[:new_photos] = session[:new_photos] || #<- i only did this after session[:new_photos] << @photo.id returned nil     params[:Filedata].content_type = File.mime_type?(params[:Filedata].original_filename)     @photo = Photo.new :uploaded_data => params[:Filedata]     @photo.save!     debugger     session[:new_photos] << @photo.id     debugger     # This returns the thumbnail url for handlers.js to use to display the thumbnail     render :text => @photo.public_filename(:thumb)   rescue     render :text => "Error" end

def x   debugger   @add_tags = Photo.find(session[:new_photos])   debugger   render :action => "edit_multiple" end

after all files are uploaded i redirect to the x method which in turn renders the general method for adding tags

the strange thing i ran into is, that session is apparently only visible in the swfupload method, although i used it without problems in other places

when i tried to debug it first there was the problem that session[:new_photos] was nil in the swfupload method, so i tried to initialize it in the first run through, that worked, although i could not access it in the x method because it was nil again (during the debugging it was clearly filled with some ids in the swfupload method) so i guess the way i did it somehow makes session a local array with scope only for swfupload but i dont know how else to do it

any suggestions would be appreciated, tia, alex

yep, swfupload, due to a bug in Flash, can't send the information necessary for Rails session handling. there are several blogs here, that handle this theme (search)

basicly there are two ideas about it: manually send the session data with the file and somehow make Rails use it. last thing i heard about it was, that someone made it run with FF but not with IE.

my approach: turn off session handling for the upload function add one more step: send a upload_request (ajax) for each file, create a record and store some random string, hand this back with the ajax response and add as parameter to swfupload:

this function will go through the files and request uploads: (for another bug it has to use the generated html (uploadQueue / file_rows) to get the file_ids)

function requestFileUploads() {   queued_files = $("uploadQueue").getElementsByClassName("file_row")   for(i = 0; i < queued_files.length; i++) {     fileObject = swf_upload_control.getFile(queued_files[i].getAttribute("name"));     new Ajax.Request("<%= request_upload_products_url %>", {       method: 'get',       evalScripts: true,       parameters: {         file_name: fileObject.name,         file_id: fileObject.id,         document_name: $("input_" + fileObject.id).value       }     });   } }

this function is called by the response:

function queue_acknowledged_files(file_id, document_id, checksum) {   swf_upload_control.addFileParam(file_id, "document_id", document_id);   swf_upload_control.addFileParam(file_id, "document_checksum", checksum);   swf_upload_control.startUpload(file_id); }

the upload function then looks for a document record with the given id and checksum, stores the file and deletes the checksum.

that's not the complete code, but i think you can get the idea