【问题标题】:Canceling all "jquery file upload" uploads does does not work when using client side resizing使用客户端调整大小时,取消所有“jquery 文件上传”上传不起作用
【发布时间】:2015-03-30 09:10:03
【问题描述】:

我正在尝试取消所有上传以调整客户端大小。我可以让其中一个工作,但不能同时工作。我一直在我的add 方法中维护一堆xhr 对象,但这需要直接调用data,submit()。我现在更改了我的代码以挂接到 fileuploadadd 并且调整大小效果很好,但取消只会取消一个文件(我假设是最新的)。

这是它目前的样子:

@addFile = (e, data) =>
  if @validate(data)
    this.transfers.push(data)
  else
    $result = $("<div class='error'>#{data.files[0].name} failed to upload. Files must be 5MB or less, and must be gif, jpg, or png format.</div>")
    $messageContainer.append($result)
    e.preventDefault()

$(input).fileupload
  disableImageResize: /Android(?!.*Chrome)|Opera/.test(window.navigator && navigator.userAgent)
  imageMaxWidth: 1024
  imageMaxHeight: 1024
  imageCrop: false
.bind('fileuploadadd', @addFile)

【问题讨论】:

    标签: jquery-file-upload


    【解决方案1】:

    感谢 dannio 和他的 post 我能够解决这个问题。这是我最终得到的,效果很好:

    class Uploader
      transfers: []
      cancelAll: ->
        for xhr in this.transfers
          xhr.abort() if xhr
        this.transfers = []
      configure: (input) ->
        configurator = this
    
        $(input).fileupload
          disableImageResize: /Android(?!.*Chrome)|Opera/.test(window.navigator && navigator.userAgent)
          imageMaxWidth: 1024
          imageMaxHeight: 1024
          imageCrop: false
          add: (e, data) =>
            if this.validate(data)
              $target = $(e.target)
              data.process(->
                return $target.fileupload('process', data)
              ).done(->
                configurator.transfers.push data.submit()
              )
      validate: (data) ->
        if typeof data.files[0].type != 'undefined' && data.files[0].size != 'undefined'
          valid = data.files[0].type in ["image/jpeg", "image/png", "image/gif"]
          valid && data.files[0].size <= 5242880
        else
          true
    

    【讨论】:

      猜你喜欢
      • 2015-06-03
      • 1970-01-01
      • 2013-11-24
      • 2010-09-30
      • 2014-05-08
      • 2015-07-20
      • 1970-01-01
      • 2014-11-29
      • 2018-09-20
      相关资源
      最近更新 更多