jquery uploadify

David picture David · Dec 2, 2009 · Viewed 14.1k times · Source

Okay, i can't post all the code to this because it's just unnecessary. But here's the problem.

I have a tabbed dialogue (ui.tabs) which contains an uploadify form for uploading files. However on an earlier tab I check the status of a radiobutton to determine whether to allow only image files or flash files.

I have initialized uploadify as such beforehand, within $(document).ready:

$("#uploadify").uploadify({params});

... including 'fileDesc' and 'fileExt' parameters. In itself, it works fine. But once it has been initialized, I wish to alter the settings using:

$("#uploadify").uploadifySettings('fileDesc','blah blah');
$("#uploadify").uploadifySettings('fileExt','.ext');

... but when i do this, Firebug spouts the following:

document.getElementById(a(this).attr("id") + "Uploader").updateSettings is not a function http://localhost/projectname/Javascript/jquery.uploadify.v2.1.0.min.js Line 26

Now obviously there is nothing wrong with uploadify itself, but I may be a total noodle here. Is this happening because it thinks that '#uploadify' hasn't been initialized yet?

Answer

Donny Kurnia picture Donny Kurnia · Jan 5, 2010

You should see accepted answer in this thread. The key is to call the $("#uploadify").uploadifySettings(); inside upload start handler, or form submit handler.

Overall, the js code should be like this:

jQuery(function($){

  //make uploadify
  $("#uploadify").uploadify({params});

  //handle form submit
  $("#form").submit(function(e){
    //prefent form submit
    e.preventDefault();

    //change the uploadify setting, ex. scriptData
    $("#uploadify").uploadifySettings("scriptData", {'file_id': '345'});

    //start upload
    $("#uploadify").uploadifyUpload();

  });
});

This code work for me, I hope it work in your case. Form submit can be replaced by another function, such as in function startUpload that exist in example script from uploadify website.