2014-10-22 78 views
3

我需要发送带参数的文件并跟踪上传进度。方法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) 
    } 

不能设置参数

是可以发送与参数和跟踪上传进度的文件?

+1

http://stackoverflow.com/a/26153191/1702413 – TonyMkenu 2014-10-23 07:15:48

+1

http://stackoverflow.com/questions/26121827/uploading-file-with-parameters-using-alamofire/26747857#26747857 – antiblank 2014-11-11 18:29:00

回答

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) 

    })