【问题标题】:Alamofire uploading progressAlamofire 上传进度
【发布时间】:2014-12-17 12:28:44
【问题描述】:

我需要发送一个带有参数的文件并跟踪上传进度。方法

Alamofire.request(.POST, "http://httpbin.org/post", parameters: parameters, encoding: .JSON)

不跟踪上传进度。方法

Alamofire.upload(.POST, "http://httpbin.org/post", file: fileURL)
     .progress { (bytesWritten, totalBytesWritten, totalBytesExpectedToWrite) in
         println(totalBytesWritten)
     }
     .responseJSON { (request, response, JSON, error) in
         println(JSON)
     }

无法设置参数

是否可以发送带有参数的文件并跟踪上传进度?

【问题讨论】:

标签: ios swift alamofire


【解决方案1】:

您必须使用 .uploadProgress 而不是 .progress

【讨论】:

    【解决方案2】:

    这样用

        activeVidoeCell.uploadRequest = Alamofire.upload(fileData as Data, to: url, method: .put, headers: nil).uploadProgress(closure: { (progress) in
    
            print(progress.fractionCompleted)
            activeVidoeCell.downloadButton.setProgress(CGFloat(progress.fractionCompleted), animated: true)
    
        }).responseJSON(completionHandler: { (result) in
    
            completionHandler(result)
    
        })
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-02-16
      • 1970-01-01
      • 2017-03-07
      • 1970-01-01
      • 2019-03-13
      • 2021-10-19
      • 2016-03-07
      相关资源
      最近更新 更多