ファイルのアップロードの進捗状況を取得するにはどうすればよいですか?Alamofireを使用してファイルアップロードに進捗状況を追加
// import Alamofire
func uploadWithAlamofire() {
let image = UIImage(named: "myImage")!
// define parameters
let parameters = [
"hometown": "yalikavak",
"living": "istanbul"
]
// Begin upload
Alamofire.upload(.POST, "upload_url",
// define your headers here
headers: ["Authorization": "auth_token"],
multipartFormData: { multipartFormData in
// import image to request
if let imageData = UIImageJPEGRepresentation(image, 1) {
multipartFormData.appendBodyPart(data: imageData, name: "file", fileName: "myImage.png", mimeType: "image/png")
}
// import parameters
for (key, value) in parameters {
multipartFormData.appendBodyPart(data: value.dataUsingEncoding(NSUTF8StringEncoding)!, name: key)
}
}, // you can customise Threshold if you wish. This is the alamofire's default value
encodingMemoryThreshold: Manager.MultipartFormDataEncodingMemoryThreshold,
encodingCompletion: { encodingResult in
switch encodingResult {
case .Success(let upload, _, _):
upload.responseJSON { response in
debugPrint(response)
}
case .Failure(let encodingError):
print(encodingError)
}
})
}
進捗ブロックを追加する必要があるとわかっていますが、進捗ブロックを追加できる場所がわかりません。
.progress { (bytesWritten, totalBytesWritten, totalBytesExpectedToWrite) in
println("\(totalBytesWritten)/\(totalBytesExpectedToWrite)")
}
上記のブロックを追加したいのですが、ビデオアップロードの推定時間を計算するにはどうすればよいですか。
uitableviewCellでアップロードの進行状況を表示するにはどうすればよいですか? –