我试图在我的项目中使用blueimp
jQuery File Upload。它适合我的需要相当不错,但我需要更改url文件被上传到动态插件的创建和配置后。我做了大量的调查,但遗憾的是没有发现任何有用的东西。一般来说,我有一个按钮来选择文件和fileupload操作来覆盖实际上传。基本的创作如下所示:
$('[upload-button]').fileupload(new FileUploadConfig())
并配置本身:
function FileUploadConfig() {
// is set to a unique value for each file upload
this.url = 'temporary';
this.fileInput = $('[upload-button]');
//... some other code
}
我需要做的是更改此配置中的URL,然后调用data.submit()。我发现这个配置是使用$ .data()保存的,并尝试解决这样的代码的问题
// 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();
但是,这不符合我想要的方式。
关于如何实现这一点的任何想法?
解决方法
只是在这里捕捉到后代。
在当前的jQuery-upload rev中,覆盖add(evt,data)函数并设置数据对象的url属性:
fileupload({
add: function(e,data) {
data.url = 'customURL'
...
},...
}