2

I'm trying to upload a short video recorded using UIImagePickerController to Amazon S3. I'm following the Amazon sample code which seems straightforward but my file is not appearing in my bucket.

I'm logging the delegate methods and strangely totalBytesWritten is smaller than totalBytesExpected.

Here is my code:

AmazonS3Client *s3 = [[AmazonS3Client alloc] initWithAccessKey:AWS_ACCESS_KEY withSecretKey:AWS_SECRET_KEY];
S3PutObjectRequest *por = [[S3PutObjectRequest alloc] initWithKey:@"test.mov" inBucket:@"mybucket"];
por.contentType = @"video/quicktime";
NSData *videoData = [NSData dataWithContentsOfURL:videoURL];
por.data = videoData;
por.delegate = self;
[s3 putObject:por];

The only delegate method getting any response is the one reporting bytes. The others aren't called.

UPDATE

If the file is very small it actually works. An 110000 byte file uploaded fine. It stops at 196608 bytes every time. If the file is smaller than that it will upload.

1 Answer 1

2

So there were two issues here. As the file is sizeable I switched to using S3TransferManager I also set the endpoints which was crucial. Final code is:

AmazonS3Client *s3 = [[AmazonS3Client alloc] initWithAccessKey:AWS_ACCESS_KEY withSecretKey:AWS_SECRET_KEY];
s3.endpoint = [AmazonEndpoints s3Endpoint:US_WEST_2];
S3TransferManager *transferManager = [S3TransferManager new];
transferManager.s3 = s3;
transferManager.delegate = self;
s3.endpoint = [AmazonEndpoints s3Endpoint:US_WEST_2];
NSData *videoData = [NSData dataWithContentsOfURL:_videoURL];
[transferManager uploadData:videoData bucket:@"bucketname" key:@"test.mov"];

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.