Reputation: 8661
I am trying to upload a file to S3 using:
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)
I see this in my console: Upload Starting! But the file never gets uploaded
Bucket permissions:
{
"Version": "2008-10-17",
"Statement": [
{
"Sid": "AddPerm",
"Effect": "Allow",
"Principal": "*",
"Action": "s3:GetObject",
"Resource": "arn:aws:s3:::myBucket/*"
}
]
}
oneClick_Cognito_MyUserUnauth_Role_xxxxxx policy:
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": [
"mobileanalytics:PutEvents",
"cognito-sync:*",
"s3:*"
],
"Resource": [
"*"
]
}
]
}
I get the error: Domain=com.amazonaws.AWSS3TransferUtilityErrorDomain Code=2
Upvotes: 2
Views: 1328
Reputation: 8661
The problem was that my Cognito user was in us region, and my bucket was in eu.
Upvotes: 1
Reputation: 502
In your bucket permission, try adding permission for s3:PutObject
Upvotes: 0