Chetan Kumar
Chetan Kumar

Reputation: 397

Hot to use jquery promise with file Upload

I am trying to upload an image using a fine Uploader plug-in and i want to send some form data along with the image but the form data is not available to me at the time of initializing the plugin(according to the requirements of the plugin it should be given at the time of initialization). Is it possible to use jquery Promise for this purpose if yes How?

/*--  Create Rack Image Uploads  --*/

$('.rack-create-modal').on('shown.bs.modal', function () {
    $('#createRackImageUpload').fineUploader({
        template: 'qq-template-manual-trigger',
        multiple: false,
        autoUpload: false,
        request: {
            endpoint: 'upload_shop_rack',
            // customHeaders:{data:$('#createRack').serialize()},
            params:{data:{ 
                            name:''//,I want promimse Here
                            value:'Human Value'
            } 
        },
        session: {
            endpoint: 'get_rack_image',
            refreshOnRequest: true,
        },
        validation: {
            allowedExtensions: ['jpeg', 'jpg', 'gif', 'png'],
            sizeLimit: 5242880,
            itemLimit: 1

        },
        messages: {
            tooManyItemsError: 'You can only add 1 image'
        },
        deleteFile: {
            enabled: true,
            forceConfirm: true,
            endpoint: 'delete_shop_rack'
        }
    });
    $('.trigger-upload').click(function (e) {
        Var createRackForM=$('#cresteRack').serialize();
        $('#createRackImageUpload').fineUploader('uploadStoredFiles');
    });
});

Upvotes: 4

Views: 568

Answers (1)

Ray Nicholus
Ray Nicholus

Reputation: 19890

You can include any parameters with any upload request at any time using Fine Uploader's setParams API method. For example:

callbacks: {
   onUpload: function(id) {
      this.setParams(id, {someData: 'someValue'})
   }
}

Upvotes: 2

Related Questions