2016-11-10 5 views
0

イメージをバケットにアップロードしようとしています。接続が確立され、アップロードは明らかに開始されますが進行しません。アンドロイドアプリがアップロードできるので、私は正しいと考えてサーバーの権限。s3バケットへのスクロールアップロードが終了しない

let credentialsProvider = AWSCognitoCredentialsProvider(regionType: AWSRegionType.USEast1, identityPoolId: "us-east-1:XXXXXX-XXXX-XXXX-XXXX-XXXX”, unauthRoleArn: "arn:aws:iam::XXXXX:role/Cognito_mybucketUnauth_Role", authRoleArn: "arn:aws:iam::XXXXX:role/Cognito_mybucketAuth_Role", identityProviderManager: nil) 

let configuration = AWSServiceConfiguration(region: AWSRegionType.USEast1, credentialsProvider: credentialsProvider) 
     AWSServiceManager.defaultServiceManager().defaultServiceConfiguration = configuration 

をそして、これは画像を取得し、

func imagePickerController(picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : AnyObject]){ 

    //getting details of image 
    let uploadFileURL = info[UIImagePickerControllerReferenceURL] as! NSURL 

    let imageName = uploadFileURL.lastPathComponent 
    let documentDirectory = NSSearchPathForDirectoriesInDomains(.DocumentDirectory, .UserDomainMask, true).first! as String 

    // getting local path 
    let localPath = (documentDirectory as NSString).stringByAppendingPathComponent(imageName!) 


    //getting actual image 
    let image = info[UIImagePickerControllerOriginalImage] as! UIImage 
    let data = UIImagePNGRepresentation(image) 
    data!.writeToFile(localPath, atomically: true) 

    let imageData = NSData(contentsOfFile: localPath)! 
    imageURL = NSURL(fileURLWithPath: localPath) 

    CampoImagem.image = image 

    picker.dismissViewControllerAnimated(true, completion: nil) 
    uploadImage() 
} 


func uploadImage(){ 

    //defining bucket and upload file name 
    let S3BucketName: String = “mybucket" 
    let S3UploadKeyName: String = "profile/testImage.jpg" 

    let expression = AWSS3TransferUtilityUploadExpression() 
    /*expression.uploadProgress = {(task: AWSS3TransferUtilityTask, bytesSent: Int64, totalBytesSent: Int64, totalBytesExpectedToSend: Int64) in 
     dispatch_async(dispatch_get_main_queue(), { 
      let progress = Float(totalBytesSent)/Float(totalBytesExpectedToSend) 
      print("Progress is: \(progress)") 
     }) 
    }*/ 


    self.uploadCompletionHandler = { (task, error) -> Void in 
     dispatch_async(dispatch_get_main_queue(), { 
      if ((error) != nil){ 
       print("Failed with error") 
       print("Error: \(error!)"); 
      } 
      else{ 
       print("Sucess") 
      } 
     }) 
    } 

    let transferUtility = AWSS3TransferUtility.defaultS3TransferUtility() 

    transferUtility.uploadFile(imageURL, bucket: S3BucketName, key: S3UploadKeyName, contentType: "image/jpeg", expression: expression, completionHander: uploadCompletionHandler).continueWithBlock { (task) -> AnyObject! in 
     if let error = task.error { 
      print("Error: \(error.localizedDescription)") 
     } 
     if let exception = task.exception { 
      print("Exception: \(exception.description)") 
     } 
     if let _ = task.result { 
      print("Upload Starting!") 
     } 

     return nil; 
    } 
} 

印刷をアップロードする:私のappdelegateで 私はこれを持っているのアップロードが開始します!

私はawsでアップロードを完了するためのIDと権限があると思っていますが、それがアップロードであれば正しかったと思いますか? どうすればこの問題を解決できますか?

答えて

0
+0

このデモプロジェクトの資格情報を追加することによって、あなたもチェックすることができ、このコードを確認してください。しかし、私のアップロードは42%でハングアップし、それが長い間エラーになります。 –

+0

デモコードで動作していますか? –

関連する問題