问题描述
我正在尝试在我的项目中使用 blueimp jQuery File Upload.它非常适合我的需求,但我需要在创建和配置插件后更改 url 文件动态上传.我做了很多调查,但不幸的是,没有发现任何有用的东西.一般来说,我有一个按钮来选择文件和覆盖实际上传的文件上传操作.基本创建如下所示:
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())
以及配置本身:
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()
保存的,并试图用这样的代码解决问题
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?
推荐答案
这里只是为了后代.
在当前 jQuery-upload rev 中,重写 add(evt,data) 函数并设置数据对象的 url 属性:
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'
...
},
...
}
这篇关于jQuery File Upload:如何动态更改上传 url的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!