jQuery File Upload:如何动态更改上传网址 [英] jQuery File Upload: how to change the upload url dynamically

查看:87
本文介绍了jQuery File Upload:如何动态更改上传网址的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在我的项目中使用blueimp jQuery文件上载.它非常适合我的需求,但是在创建和配置插件之后,我需要更改将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?

推荐答案

这里只是为了后代而已.

Just capturing this here for posterity.

在当前的jQuery上传版本中,重写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:如何动态更改上传网址的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆