Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jQuery File Upload: how to change the upload url dynamically

Tags:

I'm trying to use the blueimp jQuery File Upload in my project. It suits my needs fairly well but I need to change the url files are uploaded to dynamically after the plugin is created and configured. I've done a good deal of investigation, but, unfortunately, found nothing useful. In general, I have a button to choose files and fileupload action covering the actual upload. The basic creation looks like this:

 $('[upload-button]').fileupload(new FileUploadConfig())  

And configuration itself:

 function FileUploadConfig() {       // is set to a unique value for each file upload      this.url = 'temporary';      this.fileInput = $('[upload-button]');       //... some other code  } 

The thing I need to do is change the url in this config and then call data.submit(). I've found out, that this configuration is saved using $.data() and tried to solve the problem with such code

// get the current fileupload configuration var config = $.data($('[upload-button]').get(0), 'fileupload');  // change the url configuration option config.options.url = file.link;  //send a file data.submit(); 

However, this does not work the way I wanted.

Any ideas on how to accomplish this?

like image 599
Arthur Avatar asked Oct 20 '12 09:10

Arthur


1 Answers

Just capturing this here for posterity.

In the current jQuery-upload rev, override the add(evt,data) function and set the url property of the the data object:

fileupload({    add: function(e, data) {       data.url = 'customURL'       ...    },    ... } 
like image 67
Bill Avatar answered Sep 22 '22 17:09

Bill