在项目中,我有两个框架:AWSRuntime和AWSS3,我用它来上传图像。
- (void)updateAWSCredentials:(NSDictionary *)AWSObject {
if(AWSObject && [AWSObject isKindOfClass:[NSDictionary class]]) {
self.key = AWSObject[@"AccessKeyId"];
self.secret = AWSObject[@"SecretAccessKey"];
self.token = AWSObject[@"SessionToken"];
self.profileImagePath = AWSObject[@"FilePrefixProfile"];
self.postImagePath = AWSObject[@"FilePrefixPost"];
self.bucket = AWSObject[@"BucketName"];
}
}
- (NSString *)uploadImageObject:(HAAmazonImageContainer *)imageObject {
NSData *imageData = UIImageJPEGRepresentation(imageObject.image, 1.0);
NSString *imageKey = [NSString stringWithFormat:@"%@_%f", imageObject.userId, [[NSDate date] timeIntervalSince1970]];
imageKey = [imageKey stringByReplacingOccurrencesOfString:@"." withString:@"0"];
NSString *imagePath = self.postImagePath;
if(imageObject.imagePath != HAAmazonPostImagePath) {
imagePath = self.profileImagePath;
}
@try{
// Create the S3 Client.
AmazonCredentials *lCredentials = [[AmazonCredentials alloc] initWithAccessKey:self.key
withSecretKey:self.secret
withSecurityToken:self.token];
AmazonS3Client *s3 = [[AmazonS3Client alloc] initWithCredentials:lCredentials];
S3PutObjectRequest *por = [[S3PutObjectRequest alloc] initWithKey:[NSString stringWithFormat:@"%@/%@.jpeg", imagePath, imageKey]
inBucket:self.bucket];
por.contentType = @"image/jpeg";
por.cannedACL = [S3CannedACL publicRead];
por.data = imageData;
por.delegate = self;
s3.endpoint = [AmazonEndpoints s3Endpoint:US_WEST_2];
[s3 putObject:por];
}
@catch (AmazonClientException *exception) {
NSLog(@"exception");
}
return [NSString stringWithFormat:@"http://%@/%@", self.bucket, [NSString stringWithFormat:@"%@/%@.jpeg", imagePath, imageKey]];
}
-(void)request:(AmazonServiceRequest *)request didCompleteWithResponse:(AmazonServiceResponse *)response {
NSLog(@"complete with response");
if([request isKindOfClass:[S3PutObjectRequest class]]) {
S3PutObjectRequest *requestObj = (S3PutObjectRequest *)request;
NSString *key = @"";
NSArray *keys = [requestObj.key componentsSeparatedByString:@"/"];
if(keys.count == 2) {
key = keys[1];
}
NSDictionary *userInfo = [[NSDictionary alloc] initWithObjectsAndKeys:key, IMAGE_KEY, nil];
[[NSNotificationCenter defaultCenter] postNotificationName:kHAAmazonDidUploadImage object:nil userInfo:userInfo];
}
}
现在我想搬到Cocoapods。我用pod 'AWSS3'
导入了AWSS3,我收到一个错误:
“无法找到'AmazonServiceRequestDelegate'的协议声明”
我在哪里找到AmazonServiceRequestDelegate声明或是否已弃用?
您正在使用适用于iOS的AWS Mobile SDK版本1。我们正式开始使用SDK的第2版支持CocoaPods,而AWSS3
仅用于下载SDK的第2版。在迁移应用程序以使用AWS Mobile SDK for iOS v2之前,您无法使用CocoaPods来安装AWS Mobile SDK。
AWS Mobile SDK for iOS Developer Guide可以帮助您开始使用SDK的第2版。请注意,它与SDK的版本1没有向后兼容性。