我在回答這個問題上看到了很多問題,但我無法正確執行,因爲文件沒有下載。如何使用ios從s3下載一組文件?
一些背景是我在s3中有一組10個文件。我可以通過S3ListObjectsResult查看它們的np。然後,我將結果存儲在一個過濾的NSMutableArray s3Result中。這一切工作正常。
後來,我竟要下載的文件,所以我試着這樣做:
在.h文件:
@interface MainViewController : UIViewController <AmazonServiceRequestDelegate>
@property (nonatomic, strong) NSMutableArray *s3Objects;
@property (nonatomic, strong) NSMutableArray *s3Results;
在.m文件:
AmazonS3Client *s3 = [[AmazonS3Client alloc] initWithAccessKey:key withSecretKey:secret];
for (NSString *result in s3Results) {
S3GetObjectRequest *s3Request = [[S3GetObjectRequest alloc] initWithKey:s3Result withBucket:bucket];
s3Request.delegate = self;
S3GetObjectResponse *s3Response = [s3 getObject:s3Request];
[s3Objects addObject:[[NSData alloc] initWithData:s3Response.body]];
這個編譯好,運行正常,但「下載」文件太快,實際上並沒有工作,事實上self.s3Objects返回計數爲0.
- 有沒有一種方法可以在S3上看到調試?
- 我在做什麼錯誤的問候獲取文件?
- 有沒有可能是因爲我在XCode模擬器中這樣做了?
編輯: 好了,我在AWS需要,即didCompleteWithResponse,didReceiveData,didFailWithError和didFailWithServiceException一些方法補充。
的結果是文件被下載的,現在(我可以打印出response.body,看看數據),但他們沒有被添加到s3Objects:
-(void)request:(AmazonServiceRequest *)request didCompleteWithResponse:(AmazonServiceResponse *)response
{
[self.s3Objects addObject:[[NSData alloc] initWithData:response.body]];
}
上self.s3Objects計數即使在此之後總是返回0。