Search code examples
jqueryfileuploadblueimp

How to set a dynamic url on blueimp/jQuery-File-Upload


I'm trying to implement this plugin, and i can't make it work with change dynamically the url, Example, once i have init the plugin:

$('#image').fileupload({...})    

I call the following method to set id:

function setUrl(id) {
    var uploadUrl = '/api/products/' + id + '/images';        
    // config upload url
    $('#image').fileupload("option", "url", uploadUrl);
}

but i've these error line:

"Uncaught Error: cannot call methods on fileupload prior to initialization; attempted to call method 'option'"

How can I solve it?


Solution

  • you could set the url in add callback, as:

    fileupload({
       add: function(e, data) {
          data.url = '/api/products/' + id + '/images';      
          ...
       },
       ...
    }