4

我想动态设置精细上传器的请求端点。例如:

$('#jquery-wrapped-fine-uploader').fineUploader({
      request: {
        endpoint: submitUrl
      },
      multiple: false,
      button: $("#uploader-button"),
      // etc...
  });

submitUrl 必须已经在页面中设置并且不能更改。我想做一些更有活力的事情,比如:

 request: {
        endpoint: function() { ($('#submitUrlField').val() }
      }

但是上面将请求发送到函数%20()%20%7B%20$(%27#submitUrlField%27).val()%20}

感谢任何知道如何做到这一点的人!

4

4 回答 4

2

您可以使用多个端点。例如,使用多个端点进行奇数/偶数上传:

        callbacks: {
            onUpload:  function(id, name) {
                var endpoint = endpoints[id % endpoints.length];
                this.setEndpoint(endpoint.url, id);
                this.setParams({
                    signature: endpoint.signature,
                    params: endpoint.params,
                    ajax: true
                }, id);
            }
        }
于 2016-03-31T12:07:02.683 回答
0

如果文件很大并且您已启用分块,则无法动态更改端点 url。我的解决方案是使用事件

callbacks:{
  onComplete:function(id,name,responseJSON,xhr) {
    console.log('> onComplete. id=' + id);
    console.log('> onComplete. name=' + name);
    console.log('> onComplete. responseJSON=' + JSON.stringify(responseJSON));
    console.log('> onComplete. uuid=' + responseJSON.uuid);

    if (responseJSON.success)
    {
      // call a httpRequest with the url you want.
    }
  }
}
于 2018-07-10T11:34:49.283 回答
0

该方法的一个有用示例setEndpoint。此代码将根据上传文件类型设置端点:

    callbacks: {
        onUpload:  function(id, name) {
            var file = this.getFile(id);
            var fileType = file.type;
            this.setEndpoint(endpointList[fileType], id);
        }
    }

你的endpointList

var endpointList = {
    'image/png': 'url/uploadimage',
    'video/mp4': 'url/uploadvideo',
    'text/plain': 'url/uploadtext'
}
于 2018-08-17T04:22:39.103 回答
-2

你的旧代码:

 request: {
        endpoint: function() { ($('#submitUrlField').val() }
      }
                               |_ why need ( becasue it has not close ) match

尝试其中之一

request: {
   endpoint: function() { return $('#submitUrlField').val() }  // here you had `(`
}

或者

request: {
   endpoint: $('#submitUrlField').val() 
}
于 2013-10-12T13:03:31.293 回答