Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Submit custom POST variables with each file

I am trying to send custom POST variables with each uploaded file.

I have it set up so that each file has 2 fields where users can enter tags and a description for that file.

The code I am using is

uploader.bind('UploadFile', function (up, file) {
    $.extend(up.settings.multipart_params, {
        'tags': $('#tags_' + file.id).val(),
        'description': $('#description_' + file.id).val()
    });
});

The above code seems to work for every file except the first.

Is this the proper way to send custom post data for individual files?

like image 244
DaveE Avatar asked Nov 04 '11 00:11

DaveE


1 Answers

UploadFile is a callback that is triggered after a file is uploaded, so you are actually setting the params of the current file for the next file.

You need to use the BeforeUpload callback to achieve what you are trying to do, this callback is executed just before any request is sent to the server, this even allows you to dynamically change the URL to where you want to upload your file.

like image 74
gonchuki Avatar answered Nov 15 '22 09:11

gonchuki