Sunday, October 4, 2009

Fixing uploadify default behavior

I found the most awesome jQuery plugin for uploading multiple files through AJAX, uploadify

The plugin itself is great and I'm going to use it in every project that involves uploading files, but I found some odd behavior in this plugin.
The core of the problem is the "fileDataName" setting, which has default value of "Filedata", which isn't debugging/coder friendly at all.

I spent some time wondering why my upload isn't working, until I noticed that what was wrong.

There is really simple solution for this, just edit jquery.uploadify.vXXX.js a little bit.
Look at line 42 (ish) for the following code
fileDataName : 'Filedata', // The name of the file collection object in the backend upload script

Replace it with:
fileDataName : jQuery(this).attr('name'), // The name of the file collection object in the backend upload script


Now the default value is automatically the input value of your file input.


I almost forgot, this plugin seems to change the mimetype of every file to application/octet-stream instead of what they are. I think this is caused by the flash uploader. If you know a fix to this, please leave a comment :)

Edit: It seems that this is default behavior for flash.