我正在以这种方式使用AWS SDK
属性声明:
@property (nonatomic, strong)AWSStaticCredentialsProvider *credentialsProvider;
@property (nonatomic, strong)AWSServiceConfiguration * configuration;
@property (nonatomic, strong)AWSS3 *s3;
@property (nonatomic, strong) AWSS3PutObjectRequest *putrequest;
以这种方式实施
AccessKeys * accessKeys = [ECSGlobals sharedInstance].accessKeys;
self.credentialsProvider = [AWSStaticCredentialsProvider credentialsWithAccessKey:accessKeys.accessKeyId secretKey:accessKeys.secretAccessKey];
self.configuration = [AWSServiceConfiguration configurationWithRegion:AWSRegionUSEast1 credentialsProvider:self.credentialsProvider];
self.s3 = [[AWSS3 alloc] initWithConfiguration:self.configuration];
self.putrequest = [AWSS3PutObjectRequest new];
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *savedImagePath = [documentsDirectory stringByAppendingPathComponent:imageName];
NSData *imageData = UIImageJPEGRepresentation(image, 0.2);
[imageData writeToFile:savedImagePath atomically:NO];
long long fileSize = [[[NSFileManager defaultManager] attributesOfItemAtPath:savedImagePath error:nil][NSFileSize] longLongValue];
self.putrequest.bucket = bucketName;
self.putrequest.key = imageName;
self.putrequest.contentType = @"image/jpeg";
self.putrequest.body = [NSURL fileURLWithPath:savedImagePath];
self.putrequest.contentLength = [NSNumber numberWithLongLong:fileSize];
[[self.s3 putObject:self.putrequest] continueWithBlock:^id(BFTask *task) {
NSLog(@"Amazon error : %@", [task error]);
return nil;
}];
但我崩溃了
[CFError retain]:消息发送到解除分配的实例0x7f2daff0
我检查过所有属性都很强大。不知道为什么我会遇到这个崩溃。
答案 0 :(得分:0)
我找到了解决方案。我们正在将此问题作为一些保存的图像路径在使用前变为零的方式。因此没有图像数据发送到AWS。
修复此问题后,图片上传成功。