OGeek|极客世界-中国程序员成长平台

标题: ios - 将文件从 iOS 上传到 Amazon S3 [打印本页]

作者: 菜鸟教程小白    时间: 2022-12-12 09:56
标题: ios - 将文件从 iOS 上传到 Amazon S3

我正在尝试将使用 UIImagePickerController 录制的短视频上传到 Amazon S3。我正在关注看似简单的 Amazon 示例代码,但我的文件没有出现在我的存储桶中。

我正在记录委托(delegate)方法,奇怪的是 totalBytesWritten 小于 totalBytesExpected。

这是我的代码:

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

获得任何响应的唯一委托(delegate)方法是报告字节。其他人没有被调用。

更新

如果文件非常小,它实际上可以工作。一个 110000 字节的文件上传正常。它每次都停在 196608 字节处。如果文件小于它就会上传。



Best Answer-推荐答案


所以这里有两个问题。由于文件很大,我切换到使用 S3TransferManager 我还设置了至关重要的端点。最终代码为:

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 - 将文件从 iOS 上传到 Amazon S3,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23725160/






欢迎光临 OGeek|极客世界-中国程序员成长平台 (http://ogeek.cn/) Powered by Discuz! X3.4