通过AFNetworking上传到亚马逊S3 [英] Uploading to Amazon-S3 via AFNetworking

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

问题描述

我有困难,经AFNetworking将文件上传到S3。当我尝试上传,我得到的回调指示文件的一小部分被上传,则回调止息,一两分钟后,我得到一个超时消息。

I'm having difficulty uploading files to S3 via AFNetworking. When I attempt to upload, I get callbacks indicating a small percentage of the file is uploaded, then the callbacks cease, and one or two minutes later I get a timeout message.

我使用 AFAmazonS3Client ,但它似乎是一个pretty的直接的子类AFHTTPClient所以似乎不太可能问题出在那里。因为我是新来的两个AFNetworking和S3,我是pretty的确定问题键入此消息:)

I'm using AFAmazonS3Client but it seems like a pretty straight forward subclass of AFHTTPClient so it seems unlikely the problem lies there. Since I'm new to both AFNetworking and S3, I'm pretty sure the problem is typing this message :)

我已经下载了AWS-IOS SDK,并能张贴他们的样品code的照片没有问题。因此,我不认为它我的S3帐户的配置错误。

I've downloaded the AWS-IOS SDK and was able to post a picture from their sample code without a problem. So I don't think its a misconfiguration of my S3 account.

推荐答案

挣扎了一下同样的问题和一些研究之后,我发现了一个解决方案,它似乎运作良好。

After struggling a bit with the same problem and a bit of research, I found a solution that seems to work well.

下载亚马逊AWS SDK为iOS,并将其添加到您的项目:

Download the Amazon AWS SDK for iOS and add it to your project:

http://aws.amazon.com/sdkforios/

接着,实现了自定义的的NSOperation 类上传测试如下解释:

Then, implement the upload test with a custom NSOperation class as explained here:

<一个href="http://stackoverflow.com/questions/8230870/using-delegates-operations-and-queues/8268376#8268376">Using代表,运营和队列

AmazonServiceRequestDelegate 的协议的关键在于得到进度更新,以类似的方式是什么 AFNetworking 一样。

The AmazonServiceRequestDelegate protocol is the key to get progress updates, in a similar fashion to what AFNetworking does.

在特定的,这个方法是我所需要的:

In particular, this method is what I needed:

-(void)request:(AmazonServiceRequest *)request didSendData:(NSInteger)bytesWritten
    totalBytesWritten:(NSInteger)totalBytesWritten
    totalBytesExpectedToWrite:(NSInteger)totalBytesExpectedToWrite;

这篇关于通过AFNetworking上传到亚马逊S3的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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