我正在尝试使用 Amazon S3 SDK 将大文件部分上传到 S3 服务器。我有以下代码:
-(void)multipartUpload:(NSData*)dataToUpload inBucket:(NSString*)bucket forKey:(NSString*)key
{
//bool using3G = ![self isWifiAvailable];
AmazonS3Client *s3 = [[AmazonS3Client alloc] initWithAccessKey:kS3ApplicationKey withSecretKey:kS3ApplicationSecret];
s3.timeout = 99999999;
@try {
//[s3 createBucketWithName:bucket];
S3InitiateMultipartUploadRequest *initReq = [[S3InitiateMultipartUploadRequest alloc] initWithKey:key inBucket:bucket];
S3MultipartUpload *upload = [s3 initiateMultipartUpload:initReq].multipartUpload;
S3CompleteMultipartUploadRequest *compReq = [[S3CompleteMultipartUploadRequest alloc] initWithMultipartUpload:upload];
int numberOfParts = [self countParts:dataToUpload];
for ( int part = 0; part < numberOfParts; part++ ) {
NSLog(@"%d", part);
NSData *dataForPart = [self getPart:part fromData:dataToUpload];
// The S3UploadInputStream was deprecated after the release of iOS6.
NSInputStream *stream = [NSInputStream inputStreamWithData:dataForPart];
S3UploadPartRequest *upReq = [[S3UploadPartRequest alloc] initWithMultipartUpload:upload];
upReq.partNumber = ( part + 1 );
upReq.contentLength = [dataForPart length];
upReq.stream = stream;
upReq.delegate = self;
S3UploadPartResponse *response = [s3 uploadPart:upReq]; // <----- null returned here :(
[compReq addPartWithPartNumber:( part + 1 ) withETag:response.etag];
}
[s3 completeMultipartUpload:compReq];
}
@catch ( AmazonServiceException *exception ) {
NSLog( @"Multipart Upload Failed, Reason: %@", exception );
}
@catch (NSException *exception) {
NSLog( @"Other exception %@", exception);
}
}
问题是 uploadPart 方法返回 null 而不是实际的服务器响应,这会导致下一行出现异常。
我已经实现了所有的委托方法来检查错误,但没有任何报告。
代码从这里复制: http: //aws.amazon.com/articles/0006282245644577
任何想法为什么它不起作用?