使用S3TransferManager AWS iOS SDK上载大文件

时间:2014-04-23 02:03:19

标签: ios amazon-web-services sdk multipart

我正在尝试使用S3TransferManager将视频从iPhone上传到AWS S3。它适用于小文件,但对于较大的文件,我收到此错误:

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}

根据我的理解,S3TransferManager将文件分解为大型文件的分段上传,然后出现问题。

我目前的政策:

{
"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"
}
]
}

要上传的代码是:

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];

任何帮助将不胜感激。

1 个答案:

答案 0 :(得分:1)

您可能会错过权限s3:GetObjectAcl

我还创建了两个单独的策略,一个用于存储桶,另一个用于内容。

Bucket Policy

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

文件政策

{
  "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/*"
      ]
    }
  ]
}

我遇到了同样的问题,上述政策对我有用。