Question

I am trying to upload video from iPhone to AWS S3 using S3TransferManager. It works fine for small files but for larger files I get this error:

Error Domain=com.amazonaws.iossdk.ServiceErrorDomain Code=400 "The operation couldn’t be completed. (com.amazonaws.iossdk.ServiceErrorDomain error 400.)" UserInfo=0x16ed0600 {requestId=856937B6CD6E14DE, exception=AmazonServiceException { RequestId:856937B6CD6E14DE, ErrorCode:InvalidRequest, Message:Key is not expected for the GET method ?uploads subresource }, errorCode=InvalidRequest}

To my understanding, S3TransferManager breaks the file into a multipart upload for larger files and something is going wrong then.

My current policy:

{
"Version": "2012-10-17",
"Statement": [
{
"Action":"s3:ListBucketMultipartUploads",
"Resource":"arn:aws:s3::: my_bucket_name",
"Effect": "Allow"
},
{
"Action": ["s3:PutObject","s3:PutObjectAcl","s3:PutObjectVersionAcl","s3:GetObject","s3:ListMultipartUploadParts","s3:AbortMultipartUpload"],
"Resource": ["arn:aws:s3:::my_bucket_name/*"],
"Effect": "Allow"
}
]
}

The code to upload is:

S3PutObjectRequest *putObjectRequest = [[S3PutObjectRequest alloc] initWithKey:my_key inBucket: my_bucket_name];
    [putObjectRequest setFilename:videoMetaData.videoFilePath];

    [putObjectRequest addMetadataWithValue:[UserSessionInfo sharedSessionInfo].userEmail forKey:@"email"];
    [putObjectRequest addMetadataWithValue:[UtilHelper formatDuration:videoMetaData.length] forKey:@"videolength"];
    [putObjectRequest addMetadataWithValue:@"Landscape" forKey:@"orientation"];
    [putObjectRequest addMetadataWithValue:[NSString stringWithFormat:@"%d", data.length] forKey:@"size"];

    putObjectRequest.contentType = @"video/quicktime";
    self.uploadFileOperation = [self.s3TransferManager upload:putObjectRequest];

Any help will be appreciated.

Was it helpful?

Solution

Looks like you might be missing the permission s3:GetObjectAcl?

I also created two separate policies, one for the bucket and another for the content.

Bucket Policy

{
  "Version": "2012-10-17",
  "Statement": [
    {
      "Sid": "Stmt1398382003000",
      "Effect": "Allow",
      "Action": [
        "s3:ListBucketMultipartUploads"
      ],
      "Resource": [
        "arn:aws:s3:::uploads"
      ]
    }
  ]
}

Files Policy

{
  "Version": "2012-10-17",
  "Statement": [
    {
      "Sid": "Stmt1398382057000",
      "Effect": "Allow",
      "Action": [
        "s3:AbortMultipartUpload",
        "s3:GetObject",
        "s3:GetObjectAcl",
        "s3:ListMultipartUploadParts",
        "s3:PutObject",
        "s3:PutObjectAcl",
        "s3:PutObjectVersionAcl"
      ],
      "Resource": [
        "arn:aws:s3:::uploads/*"
      ]
    }
  ]
}

I had the same issue, and the above policies worked for me.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top