2013-07-15 95 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)無法在類方法(每類)中訪問。您需要實例化對象才能訪問對象屬性;)