Alamofire上传进度

时间:2014-10-22 05:41:01

标签: ios swift alamofire

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

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)
     }

无法设置参数

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

2 个答案:

答案 0 :(得分:2)

您必须使用.uploadProgress代替 .progress

答案 1 :(得分:0)

使用这种方式

    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)

    })