2017-03-22 37 views
1

我試圖將文件上傳到S3:斯威夫特IOS試圖上傳文件到S3,但文件永遠不會被使用上傳

func uploadImage(with data: Data) { 
     let expression = AWSS3TransferUtilityUploadExpression() 
     expression.progressBlock = progressBlock 

     transferUtility.uploadData(
      data, 
      bucket: "MyBucket", 
      key: "img.jpg", 
      contentType: "image/jpeg", 
      expression: expression, 
      completionHandler: completionHandler).continueWith { (task) -> AnyObject! in 
       if let error = task.error { 
        print("Error: \(error.localizedDescription)") 
        self.statusLabel.text = "Failed" 
       } 

       if let _ = task.result { 
        self.statusLabel.text = "Generating Upload File" 
        print("Upload Starting!") 
        // Do something with uploadTask. 
       } 

       return nil; 
     } 
    } 


self.uploadImage(with: imageData) 

我看到這在我的控制檯:上傳開始!但該文件從來沒有被上傳

區權限:

{ 
    "Version": "2008-10-17", 
    "Statement": [ 
     { 
      "Sid": "AddPerm", 
      "Effect": "Allow", 
      "Principal": "*", 
      "Action": "s3:GetObject", 
      "Resource": "arn:aws:s3:::myBucket/*" 
     } 
    ] 
} 

oneClick_Cognito_MyUserUnauth_Role_xxxxxx政策:

{ 
    "Version": "2012-10-17", 
    "Statement": [ 
     { 
      "Effect": "Allow", 
      "Action": [ 
       "mobileanalytics:PutEvents", 
       "cognito-sync:*", 
       "s3:*" 
      ], 
      "Resource": [ 
       "*" 
      ] 
     } 
    ] 
} 

我得到的錯誤:Domain=com.amazonaws.AWSS3TransferUtilityErrorDomain Code=2

回答

0

問題是我的Cognito用戶在我們地區,我的桶在歐盟。

0

在你的水桶許可,嘗試添加權限s3:PutObject

+0

我添加了它,但我仍然得到:Domain = com.amazonaws.AWSS3TransferUtilityErrorDomain Code = 2 – user2722667