2016-05-31 84 views
1

我有2個應用程序,一個在swift中,另一個在objective-c中,我使用cognito與s3進行身份驗證,但最後一天這個功能停止工作我知道爲什麼了,我的控制檯應用程序說「請求超時」,但我不會改變任何東西。應用開始上傳,但在39%或14%總是停止並凍結上傳,這是我的代碼:S3停止上傳文件iOS

應用程序的委託:

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 
} 

謝謝!

回答

0

是設備的日期時間,總是需要正確的小時數