0

我在亚马逊 s3 存储桶中上传我的图像。我在一个单独的类 Amazons3 中编写我的代码,我得到一个在类方法中访问的错误实例变量 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];
 }
4

1 回答 1

1

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

您的错误非常不言自明:无法在类方法(每个类)中访问实例属性(每个对象)。您需要一个实例化对象来访问对象属性;)

于 2013-07-15T09:42:42.747 回答