I am using Alamofire code for uploading youtube video. Everything works fine. But suppose if while uploading, I switch off my net, my uploading stops but does not give me any error in response. I am posting my code below:
alamoFireManager.upload(multipartFormData: { (MultipartFormData) in
let snippetValueDictionary = requestType.params
let statusValueDictionary = ["privacyStatus":"private"]
let videoMetaDictionary = ["snippet":snippetValueDictionary,"status":statusValueDictionary]
do{
let json = try JSONSerialization.data(withJSONObject: videoMetaDictionary, options: JSONSerialization.WritingOptions.prettyPrinted)
MultipartFormData.append(json, withName: "snippet", mimeType: "application/json")
}
catch{
}
MultipartFormData.append(localVideoURL, withName: "video", fileName: "video.mp4", mimeType: "application/octet-stream")
}, to: urlYoutube, method: .post, headers: requestType.headers, encodingCompletion: { (result) in
switch result {
case .success(let upload, _, _):
upload.uploadProgress(closure: { progress in
print("Upload Progress: \(progress.fractionCompleted)")
}).validate().responseJSON(completionHandler: { dataResponse in
if dataResponse.result.error != nil {
print("Error Description: \(dataResponse.result.error?.localizedDescription)")
}
else {
let json = JSON(dataResponse.result.value!)
print(json)
}
})
case .failure(let encodingError):
print(encodingError)
}
})
When I switch off my net, the uploading stops. When I switch it back on, the uploading restarts again and upload progress is called. When the internet is not available while data is being uploaded, I need some error in response so that user is informed about network! Can you please suggest what I may be doing wrong here?