S3停止上传文件iOS

时间:2016-05-31 19:13:59

标签: ios swift amazon-web-services amazon-s3

我有2个应用程序,一个在swift中,另一个在objective-c中,我使用cognito对s3进行身份验证,但是这个功能停止工作的最后几天我知道为什么,我的应用程序的控制台说& #34;请求超时"但我什么都不做改变。应用程序开始上传但始终停止在39%或14%并冻结上传,这是我的代码:

App代表:

    let credentialsProvider = AWSCognitoCredentialsProvider(regionType:.USEast1,
        identityPoolId:poolId)
    AWSLogger.defaultLogger().logLevel = .Verbose

    let configuration = AWSServiceConfiguration(region:.SAEast1, credentialsProvider:credentialsProvider)

    AWSServiceManager.defaultServiceManager().defaultServiceConfiguration = configuration

PhotoViewController

 let uploadRequest = AWSS3TransferManagerUploadRequest()
 uploadRequest.bucket = "bucket"
 uploadRequest.ACL = AWSS3ObjectCannedACL.PublicRead
 uploadRequest.key = "\(self.userLogin.customer_subdomain)/photos/\(imageName)"
 uploadRequest.contentType = "image/png"
 uploadRequest.body = url

 uploadRequest.uploadProgress = { (bytesSent:Int64, totalBytesSent:Int64,  totalBytesExpectedToSend:Int64) -> Void in
     dispatch_sync(dispatch_get_main_queue(), {() -> Void in
         self.updateLabel(totalBytesSent,totalBytesExpectedToSend: totalBytesExpectedToSend)
     })
 }

 AWSS3TransferManager.defaultS3TransferManager().upload(uploadRequest).continueWithBlock { (task) -> AnyObject! in
     if (task.error != nil) {
         //failed
         dispatch_async(dispatch_get_main_queue()) {
                        self.dismissViewControllerAnimated(false, completion: nil)
             let refreshAlert = UIAlertController(title: "Error", message: "Error al intentar subir el archivo", preferredStyle: UIAlertControllerStyle.Alert)
             refreshAlert.addAction(UIAlertAction(title: "OK", style: .Default, handler: nil))
             self.presentViewController(refreshAlert, animated: true, completion: nil)
         }
         print(task.error!)
     } else {
         let dic=["file":"\(self.userLogin.customer_subdomain)/photos/\(imageName)"]
         let jsonData = try! NSJSONSerialization.dataWithJSONObject(dic, options: [])
         let jsonString = NSString(data: jsonData, encoding: NSUTF8StringEncoding)! as String

         let con:URLConnection
         con=URLConnection.init()
         con.delegate=self
         let headers=["X-Auth-Token":self.userLogin.api_token]
         con.connect(self.userLogin.customer_url+"/rest/activities/\(self.activity.id)/photos",method:"POST",json: jsonString, headers: headers)
         self.imgName = "\(self.userLogin.customer_subdomain)/photos/\(imageName)"               
     }
     return nil
}
谢谢你!

1 个答案:

答案 0 :(得分:0)

是设备的日期时间,始终需要是正确的小时