ios upload file to amazon s3

I am working on an ios app that needs to be able to upload files to amazon s3 but I am having some issues. The function manages to create the correct key or path within the s3 bucket but the file itself does not upload into it. below is the code for 1 of the options i have tried

if (self.s3 == nil) {
        self.s3 = [[AmazonS3Client alloc] initWithAccessKey:[Config getS3Key] withSecretKey:[Config getS3Secret]] ;

    }
  [self performSelectorInBackground:@selector(processBackgroundThreadUploadInBackground:)
                           withObject:params];

}


- (void)processBackgroundThreadUploadInBackground:(NSMutableDictionary *)params
{


    S3PutObjectRequest *por = [[S3PutObjectRequest alloc] initWithKey:@"staging/videos/" inBucket:@"aaa.aaaaa.com"];
    por.contentType = @"video/mp4";
    por.data        = [NSData dataWithContentsOfURL:[NSURL URLWithString:[params valueForKey:@"takeurl"]]];

//    por.contentType = @"image/png";
//    por.data        = [params valueForKey:@"takeimage"];


    S3PutObjectResponse *putObjectResponse = [self.s3 putObject:por];
    [self performSelectorOnMainThread:@selector(showCheckErrorMessage:)
                           withObject:putObjectResponse.error
                        waitUntilDone:NO];
}

this creates the key path staging/videos/ within the bucket on s3 but the file is not there. I tried this with an image file also. I have checked to make sure that the data that i am trying to push up is not nil. The xml response i get from the server says that the content length is 0 though. I have also tried the multi part approach from the s3 sdk with the same result. Can anyone see what I am doing wrong ?


I'm obviously really late with this response, but just in case anyone else has this problem in the future, you were structuring your request wrong.

By doing:

S3PutObjectRequest *por = [[S3PutObjectRequest alloc] initWithKey:@"staging/videos/" inBucket:@"aaa.aaaaa.com"];

with a backslash at the end of your key, you were creating a folder, not a file. You need to end your key with the filename including a suffix, ex @"staging/videos/video.mp4" .

链接地址: http://www.djcxy.com/p/94616.html

上一篇: Amazon EC2,S3,REST API以及如何向用户正确提供内容

下一篇: ios上传文件到亚马逊S3