从iOS的上传文件到Amazon S3 [英] Upload file from iOS to Amazon S3

查看:1713
本文介绍了从iOS的上传文件到Amazon S3的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想上传使用的UIImagePickerController到Amazon S3录制视频短片。我下面亚马逊样品code这似乎简单,但我的文件没有出现在我的水桶。

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.

我登录的委托方法和奇怪totalBytesWritten比totalBytesExpected小。

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

下面是我的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.

更新

如果该文件是非常小的它的实际工作。一个110000字节的文件上传罚款。它停在196608字节每次。如果该文件是小于它将上传

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.

推荐答案

所以,有两个问题。由于该文件是相当大的,我切换到使用 S3TransferManager 我还设置这是至关重要的端点。最后code是:

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

这篇关于从iOS的上传文件到Amazon S3的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆