如何在blueimp / jQuery-File-Upload上设置动态URL

时间:2015-07-12 13:46:42

标签: jquery file upload blueimp

我正在尝试实现此插件,我无法使其动态更改网址, 例如,一旦我启动了插件:

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

我调用以下方法来设置id:

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

但我有这些错误行:

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

我该如何解决?

1 个答案:

答案 0 :(得分:3)

您可以在add回调中设置网址,如下:

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