Friday, October 30, 2015

Filepicker.io run the sucess function twice

I am using filepicker.io to upload the file in my rails application. What i am doing is first upload the file to s3 using filepicker.io, after successfully upload post the data to my server. i Am doing all these by binding a click event through jquery.

$('a.upload_file').off('click').on('click', function (event) {
     filepicker.setKey('MY FILEPICKER KEY');
     filepicker.pickAndStore({extensions: '.pdf'},
            {location: 'S3'},
            function (uploadedObjects) {
                // send request to server 
            },
            function (FPError) {
                console.log(FPError.toString());
            }
        );
    })
 
 
As in rails turbolink comes into picture which not request for javascript.
i will start calling the pickandstore function twice.
 
what i did wasremove the set key from the function it fix the issue.