Uploading to Amazon-S3 via AFNetworking

安稳与你 提交于 2019-12-09 01:09:09

问题


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.

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 :)

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.


回答1:


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

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

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

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

Using delegates, operations, and queues

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;


来源:https://stackoverflow.com/questions/10508848/uploading-to-amazon-s3-via-afnetworking

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!