2016-11-10 85 views
0

我正尝试将图像上传到存储桶。连接完成后,上传显然开始,但没有进展。我认为服务器上的权限是正确的,因为Android应用程序能够上传。 在我的appdelegate我有这样的:迅速上传到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; 
    } 
} 

打印:上传开始!

我怀疑这是当ID和许可完成与aws上传的东西,但我认为如果这是上传不会启动,更正? 我该如何解决这个问题?

回答