我在amazon s3 bucket中上传我的图片。我在一个单独的类Amazons3中编写我的代码, 我在类method.how中获取了一个错误实例变量s3来解决这个错误。我正在为变量初始化创建一个构造函数。你们可以帮助我。
-(id) init
{
self = [super init];
if(self)
{
if(self.s3 == nil)
{
// Initial the S3 Client.
self.s3 = [[AmazonS3Client alloc] initWithAccessKey:ACCESS_KEY_ID withSecretKey:SECRET_KEY];
}
}
return self;
}
+(void)uploadImage:(Products *)product
{
NSData *uploadData = [NSData dataWithContentsOfFile:[Util getFilePathForFileName:[NSString stringWithFormat:@"%@ios.mp4",product.productImageUrl]]];
S3PutObjectRequest *por = [[S3PutObjectRequest alloc] initWithKey:[NSString stringWithFormat:@"%@.mp4",product.productImageUrl] inBucket:BUCKET_NAME];
por.contentType = @"application/octet-stream";
por.cannedACL = [S3CannedACL publicRead];
por.data = uploadData;
S3PutObjectResponse *putObjectResponse = [s3 putObject:por];
if(putObjectResponse.error !=nil)
[self performSelectorOnMainThread:@selector(showCheckErrorMessage:) withObject:putObjectResponse.error waitUntilDone:NO];
}
答案 0 :(得分:1)
您的uploadImage:
可能必须是实例方法。将其签名更改为-(void)uploadImage:(Products *)product
。
您的错误非常自我解释:无法在类方法(每个类)中访问实例属性(每个对象)。您需要一个instanced对象来访问对象属性;)