AWS IOS SDK 1.0.1 中的 S3RequestDelegate 方法未针对 S3GetObjectRequest 运行
我编写了一个快速的 Objective-C 方法,该方法使用 Amazon 的 AWS iOS SDK 从我的 iPad 应用程序中的 Amazon S3 存储桶同步下载文件。这是一个企业应用程序,我使用可达性来检测 WiFi,然后再允许与 S3 同步。它对于短下载(以千字节为单位)工作正常,但对于大约 20-30 兆的文件,它将继续下载到流中,并且文件将继续增长。我没有让它去看看它是否最终会停止/崩溃,但我在我的 iOS 模拟器中看到一个 30 兆的文件超过了 90 兆。我读过几个冷酷的话题,其中一些人也经历过同样的事情,我真的需要一个答案。
这是我的方法...
- (void)retrieveRemoteFile:(NSString *)fileName {
NSString *destinationFileName = [NSString stringWithFormat:@"%@%@",[self getBucketDirectory],fileName];
AmazonS3Client *s3 = [[[AmazonS3Client alloc] initWithAccessKey:ACCESS_KEY_ID withSecretKey:SECRET_KEY] autorelease];
NSOutputStream *stream = [[NSOutputStream alloc] initToFileAtPath:destinationFileName append:NO];
[stream scheduleInRunLoop:[NSRunLoop currentRunLoop] forMode:NSDefaultRunLoopMode];
[stream open];
S3GetObjectRequest *request = [[S3GetObjectRequest alloc] initWithKey:fileName withBucket:BUCKET];
request.outputStream = stream;
[s3 getObject:request];
[stream close];
[stream release];
[request release];
}
重新评估情况,我真的很想使用异步请求来获取我的方法,并使用 S3RequestDelegate 对象来帮助我在下载时更新 bytesIn。在他们的存档中,S3AsyncViewController 中有一个示例,应该显示如何执行我想要的操作。我已将 S3RequestDelegate.h/.m 添加到我的项目中,并在我的 .h 中实现了一个 S3RequestDelegate,如下所示...
#import "S3RequestDelegate.h"
... {
S3RequestDelegate *s3Delegate;
}
我已更改了我的retrieveRemoteFile 方法,使其看起来有点像这样(它已经改变了一整天,我还没有 如您所见
- (void)retrieveRemoteFile:(NSString *)fileName {
NSString *destinationFileName = [NSString stringWithFormat:@"%@%@",[self getBucketDirectory],fileName];
AmazonS3Client *s3 = [[[AmazonS3Client alloc] initWithAccessKey:ACCESS_KEY_ID withSecretKey:SECRET_KEY] autorelease];
NSOutputStream *stream = [[NSOutputStream alloc] initToFileAtPath:destinationFileName append:NO];
//[stream scheduleInRunLoop:[NSRunLoop currentRunLoop] forMode:NSDefaultRunLoopMode];
//[stream open];
S3GetObjectRequest *request = [[S3GetObjectRequest alloc] initWithKey:fileName withBucket:BUCKET];
request.outputStream = stream;
s3Delegate = [[S3RequestDelegate alloc] init];
[request setDelegate:s3Delegate];
[s3 getObject:request];
//[stream close];
//[stream release];
//[request release];
}
,我已使用 setDelegate 将 S3GetObjectRequest 委托设置为我的 S3RequestDelegate 指针 s3Delegate。我已在 S3RequestDelegate 对象的所有委托方法中添加了断点,但它们都没有执行。在我的模拟器上查找收到的文件时,现在甚至没有下载任何内容。
该示例看起来您所需要做的就是设置一个委托以使其异步。它还使您看起来不需要管理流对象,并且无论您是否这样做,都不会下载任何内容。我正在设置委托,但它从未运行任何委托方法; didReceiveResponse、didCompleteWithResponse、didReceiveData、didSendData、totalBytesExpectedToWrite、didFailWithError 或 didFailWithServiceException。
I wrote a quick objective-C method that uses Amazon's AWS iOS SDK to synchronously download a file from my Amazon S3 Bucket in my iPad app. This is an enterprise app, and I am using reachability to detect WiFi before allowing synchronization with S3. It is working fine for short downloads (those in kilobytes), but with files that are around 20-30 megs, it will continue to download into the stream and the file will continue growing. I've not let it go to see if it will eventually stop/crash, but I've watched a file that was 30 megs go past 90 megs in my iOS Simulator. I've read into several cold threads where some have experienced the same and I really need an answer.
Here is my method...
- (void)retrieveRemoteFile:(NSString *)fileName {
NSString *destinationFileName = [NSString stringWithFormat:@"%@%@",[self getBucketDirectory],fileName];
AmazonS3Client *s3 = [[[AmazonS3Client alloc] initWithAccessKey:ACCESS_KEY_ID withSecretKey:SECRET_KEY] autorelease];
NSOutputStream *stream = [[NSOutputStream alloc] initToFileAtPath:destinationFileName append:NO];
[stream scheduleInRunLoop:[NSRunLoop currentRunLoop] forMode:NSDefaultRunLoopMode];
[stream open];
S3GetObjectRequest *request = [[S3GetObjectRequest alloc] initWithKey:fileName withBucket:BUCKET];
request.outputStream = stream;
[s3 getObject:request];
[stream close];
[stream release];
[request release];
}
Re-evaluating the situation, I'd really like to get my method using an ASynchronous Request and use a S3RequestDelegate object to help me update the bytesIn as it's downloading. In their archive, there is a sample in S3AsyncViewController that should show how to do what I want. I've added S3RequestDelegate.h/.m into my project, and implemented a S3RequestDelegate in my .h like this...
#import "S3RequestDelegate.h"
... {
S3RequestDelegate *s3Delegate;
}
I've altered my retrieveRemoteFile method to look a little like this (it's changed all day and I haven't gotten anywhere)
- (void)retrieveRemoteFile:(NSString *)fileName {
NSString *destinationFileName = [NSString stringWithFormat:@"%@%@",[self getBucketDirectory],fileName];
AmazonS3Client *s3 = [[[AmazonS3Client alloc] initWithAccessKey:ACCESS_KEY_ID withSecretKey:SECRET_KEY] autorelease];
NSOutputStream *stream = [[NSOutputStream alloc] initToFileAtPath:destinationFileName append:NO];
//[stream scheduleInRunLoop:[NSRunLoop currentRunLoop] forMode:NSDefaultRunLoopMode];
//[stream open];
S3GetObjectRequest *request = [[S3GetObjectRequest alloc] initWithKey:fileName withBucket:BUCKET];
request.outputStream = stream;
s3Delegate = [[S3RequestDelegate alloc] init];
[request setDelegate:s3Delegate];
[s3 getObject:request];
//[stream close];
//[stream release];
//[request release];
}
As you can see, I've set the S3GetObjectRequest delegate with setDelegate to my S3RequestDelegate pointer s3Delegate. I've added breakpoints in all of the delegate methods of the S3RequestDelegate object, but none of them are executing. In looking for a received file on my simulator, nothing is even getting downloaded now.
The sample makes it look like all you need to do is set a delegate to make it asynchronous. It also makes it look like you don't need to manage the stream object, and whether you do or not, nothing gets downloaded. I'm setting the delegate and it's never running any of the delegate methods; didReceiveResponse, didCompleteWithResponse, didReceiveData, didSendData, totalBytesExpectedToWrite, didFailWithError or didFailWithServiceException.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我正在设置在 OperationsQueue 中运行的请求。删除了此代码并启动主线程上的异步传输,委托函数处理传输数组中的下一个文件。我加入了状态栏和取消按钮,效果很好。
I was setting up my request to run in an OperationsQueue. Removed this code and kick off the Asynchronous transfer on the main thread and the delegate functions handle transferring the next file in the array. I've incorporated a status bar and cancel button and it worked out great.