Amazon S3的IOS下载进度条 [英] amazon s3 ios download progress bar

查看:93
本文介绍了Amazon S3的IOS下载进度条的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我工作的iOS应用程序,从Amazon S3的下载图像。我试图跟踪图像的下载进度。

I am working on an iOS application that downloads images from amazon s3. I am trying to track progress of an image download.

我不能让 - (无效)要求:(AmazonServiceRequest *)要求didSendData:(NSInteger的)bytesWritten totalBytesWritten:(NSInteger的)totalBytesWritten totalBytesExpectedToWrite:(NSInteger的)totalBytesExpectedToWrite 委托方法火。

I can not get the -(void)request:(AmazonServiceRequest *)request didSendData:(NSInteger)bytesWritten totalBytesWritten:(NSInteger)totalBytesWritten totalBytesExpectedToWrite:(NSInteger)totalBytesExpectedToWrite delegate method to fire.

这是在code,我有这么远来设置委托方法。

This is the code that I have so far to set the delegate method.

-(void) viewDidLoad
{
self.s3 = [[AmazonS3Client alloc] initWithAccessKey:ACCESS_KEY_ID withSecretKey:SECRET_KEY];
self.s3.endpoint = [AmazonEndpoints s3Endpoint:US_WEST_2];

NSString *key = [[NSString alloc] initWithFormat:@"path1/%@", uniqueID];

S3GetObjectRequest *downloadRequest = [[S3GetObjectRequest alloc] initWithKey:key withBucket: PICTURE_BUCKET];
[downloadRequest setDelegate:self];

MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:self.view animated:YES];
hud.labelText = @"Loading Picture...";
S3GetObjectResponse *downloadResponse = [s3 getObject:downloadRequest];   
}

-(void)request:(AmazonServiceRequest *)request didSendData:(NSInteger)bytesWritten totalBytesWritten:(NSInteger)totalBytesWritten totalBytesExpectedToWrite:(NSInteger)totalBytesExpectedToWrite
{
NSLog(@"Bytes Written: %i", bytesWritten);
NSLog(@"Total Bytes Written: %i", totalBytesWritten);
NSLog(@"Total Bytes Expected to Write: %i", totalBytesExpectedToWrite);
}

我设法得到这个委托方法的工作,上传图像,但似乎无法得到它的工作进行下载。什么是我需要做不同跟踪下载进度?

I managed to get this delegate method to work for uploading images, but can not seem to get it to work for downloading. What do I need to do differently to track download progress?

感谢

推荐答案

我碰到这个,而在AWS上研究自己,以为我会发布一个答案。 - (无效)要求:(AmazonServiceRequest *)要求didSendData:(NSInteger的)bytesWritten totalBytesWritten:(NSInteger的)totalBytesWritten totalBytesExpectedToWrite:(NSInteger的)totalBytesExpectedToWrite 只发送数据时,根据该名工作。

I came across this while researching myself on AWS and thought I would post an answer. -(void)request:(AmazonServiceRequest *)request didSendData:(NSInteger)bytesWritten totalBytesWritten:(NSInteger)totalBytesWritten totalBytesExpectedToWrite:(NSInteger)totalBytesExpectedToWrite only works when sending data, as per the name.

如果你有多大的文件是一个球场(你可以建立某种形式的服务器要求在开始下载前得到这些信息,或者如果有一个典型的量)。然后,你可以使用 - (无效)要求:(AmazonServiceRequest *)要求didReceiveData:(NSData的*)数据,并继续将数据追加到 @物业 NSMutableData 致电 [self.data这样appendData:数据] ,然后测量 self.data.length 返回字节的元数据大小的估计,你可以转换为字节数。

If you have a ballpark on how big the file is (you could set up some sort of server request to get this information before starting the download, or if there is a typical amount). Then you could use -(void)request:(AmazonServiceRequest *)request didReceiveData:(NSData *)data and continue to append the data to an @property of NSMutableData by calling [self.data appendData:data], then measure self.data.length which returns the number of bytes to your meta data size estimate which you could convert to bytes.

希望这有助于!

这篇关于Amazon S3的IOS下载进度条的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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