上传多部分数据(youTube视频)时出现网络错误而未给出错误响应

时间:2017-04-06 11:23:33

标签: ios swift3 alamofire youtube-data-api

我正在使用Alamofire代码上传YouTube视频。一切正常。但是假设在上传时,我关闭了我的网,我的上传停止了,但没有给我任何错误的响应。我在下面发布我的代码:

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)

            }
        })

当我关闭网络时,上传停止。当我重新打开时,上传会再次重新启动并调用上传进度。当数据上传时互联网不可用时,我需要回复一些错误,以便用户了解网络!你能否在这里建议我可能做错了什么?

0 个答案:

没有答案