1
votes

I'm using the Uploadify script on my site and I'm trying to set the scriptData parameter based on some form fields. This is the HTML/JS:

<script type="text/javascript">

    function UploadFile() {
        $('#file_upload').uploadifySettings({
            scriptData: $('#uploadForm').serializeObject()
        });

        $('#file_upload').uploadifyUpload();
    }

    $(document).ready(function () {
        $('#file_upload').uploadify({
            'uploader': '/Scripts/uploadify/uploadify.swf',
            'script': '/File/Upload',
            'cancelImg': '/Scripts/uploadify/cancel.png',
            'folder': '/uploads',
            'fileExt': '*.doc, *.pdf',
            'buttonText': 'Select File',
            'auto': false,
            'onSelect': function (event, ID, fileObj) {
                $('#uploadForm #FileName').val(fileObj.name);           
            }
        });
    });
</script>
<form id="uploadForm">
<div><label for="Description">Description</label> <input id="Description" name="Description" type="text" value="" /></div>
<div><label for="FileName">File Name</label> <input id="FileName" name="FileName" type="text" value="" /></div>    <input id="file_upload" name="file_upload" type="file" />
<button onclick="UploadFile();" type="button">Upload</button>
</form>

serializeObject is just using the serializeobject jQuery plugin to turn the form values into a json object

It uploads the file fine, but nothing in scriptData gets sent. I've checked in fiddler & the only form values are the ones from the uploadify script: folder, fileext, Filedata & Upload.

3

3 Answers

2
votes

I've had the same problem. My solution was to add an onSelectOnce handler that build the appropriate scriptData object and then called uploadifySettings to attach it. Something like this should work in your case:

onSelectOnce: function() {
    var data = $('#uploadForm').serializeObject();
    $('#file_upload').uploadifySettings('scriptData', data);
    return true;
}

A bit of a kludge but it got it working for me.

0
votes

Aaargh, so I just didn't read the doco properly, I was doing this to set the scriptData:

$('#file_upload').uploadifySettings({
    scriptData: $('#uploadForm').serializeObject()
});

When what I needed to be doing was

$('#file_upload').uploadifySettings('scriptData', $('#uploadForm').serializeObject());

It now works

0
votes

I wear this:

 'formData' : {
 'data'      : 'Hello Word',
 'timestamp' : '2020-05-30 16:06:30',
 'token'     : '59284aa85709ddaf3bd246030060f6a2'
},