2013-07-15 76 views
0

上传我的图像在亚马逊s3 bucket.im在一个单独的类中编写我的代码Amazons3, 我得到一个错误实例变量s3在类method.how中访问来解决此错误.im为变量初始化创建一个构造函数。您可以帮我解决问题。在类方法中访问的实例变量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]; 
} 

回答

1

您的uploadImage:可能必须是实例方法。将其签名更改为-(void)uploadImage:(Products *)product

你的错误是很自我解释的:一个实例属性(per-object)无法在类方法(每类)中访问。您需要实例化对象才能访问对象属性;)