1

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 Answers 3

2

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.

Sign up to request clarification or add additional context in comments.

1 Comment

Sadly that didn't help, also I can't guarantee when the users will select the file in the form so they may edit form fields after selecting the file
0

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

1 Comment

The thing I ran into was trying to set scriptData in the $(x).uploadify() call. I couldn't make it work even though TFM says it should.
0

I wear this:

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.