mardi 28 juillet 2015

S3 video upload fails with AWS sdk v2 using Swift

I am trying to upload video files to S3 using the latest (v2.2.2) AWS SDK. It works perfectly on WiFi but for some unknown reason it stalls on 3G every time at the same place. Looking at the verbose debug output it seems like it gets to 5 chunks each time which seems oddly consistent.

My upload code is:

let credentialsProvider = CustomAmazonCredentialsProvider(accessKey: json["credentials"]["key"].stringValue, secretKey: json["credentials"]["secret"].stringValue, sessionKey: json["credentials"]["token"].stringValue)

            let configuration : AWSServiceConfiguration = AWSServiceConfiguration(region: AWSRegionType.EUWest1, credentialsProvider: credentialsProvider)
            configuration.maxRetryCount = 10;



            AWSServiceManager.defaultServiceManager().defaultServiceConfiguration = configuration

            let filePath : String! = json["file_path"].stringValue

            AWSS3.registerS3WithConfiguration(configuration, forKey: filePath)

            AWSS3TransferManager.registerS3TransferManagerWithConfiguration(configuration, forKey: filePath)

            let uploadRequest : AWSS3TransferManagerUploadRequest = AWSS3TransferManagerUploadRequest()

            let file : String = json["file_path"].stringValue

            uploadRequest.body = NSURL(fileURLWithPath: self.videoPath!) //self.moviePlayer!.contentURL
            uploadRequest.key = file
            uploadRequest.bucket = json["bucket"].stringValue

            self.uploadRequests.append(uploadRequest)

            self.transferManager  = AWSS3TransferManager.S3TransferManagerForKey(json["file_path"].stringValue)


            uploadRequest.uploadProgress = {[unowned self](bytesSent:Int64,
                totalBytesSent:Int64, totalBytesExpectedToSend:Int64) in

                dispatch_sync(dispatch_get_main_queue(), { () -> Void in

                    var progress : CGFloat = CGFloat(totalBytesSent) / CGFloat(totalBytesExpectedToSend)
                    println("prog \(progress)")

                    println("total \(totalBytesSent)")
                    println("total \(totalBytesExpectedToSend)")

                    if ( progress < 1.0 ) {
                        SVProgressHUD.showProgress(Float((CGFloat(totalBytesSent) / CGFloat(totalBytesExpectedToSend))), status: "Uploading", maskType: SVProgressHUDMaskType.None)


                    }
                })

            }



            self.transferManager!.upload(uploadRequest).continueWithBlock({ (task) -> AnyObject! in
            ...
          })

I'm pretty sure I have references to everything and as I said, it works perfectly on WiFi so why would it fail consistently at 5 chunks on mobile network?




Aucun commentaire:

Enregistrer un commentaire