Amazon S3 copy object between buckets in Objective C

I'm building a Mac OSX command line tool to handle basic S3 object operations. I can successfully put/retrieve/delete an object but have trouble copying objects.

When I run the project, it crashes and point me to the dealloc method in S3Response.m. But when I check my S3 console online, the object is copied without a problem. Any idea how to prevent the crash? Thanks! Here is my code:

void copyObjectAcrossAWSS3(NSString *sourceFile, NSString *sourceBucket, NSString *destinationFile, NSString *destinationBucket)
{
    @try {
        S3CopyObjectRequest *copyObjectRequest = [[S3CopyObjectRequest alloc] initWithSourceKey:sourceFile 
                                                                           sourceBucket:sourceBucket 
                                                                         destinationKey:destinationFile 
                                                                      destinationBucket:destinationBucket];
        // The request has default S3cannedACL property as private: Owner gets FULL_CONTROL. No one else has access rights (default).
        copyObjectRequest.metadataDirective = @"COPY";
        [[RAWSCommon s3] copyObject:copyObjectRequest];
        NSLog(@"copyObjectAcrossAWSS3: request sent");
    } @catch (NSException *exception) {
        NSLog(@"Failed to copy Object [%@]", exception);
    }
}


int main(int argc, const char * argv[])
{
    @autoreleasepool {
       copyObjectAcrossAWSS3(@"source file", @"source bucket", @"destination file", @"destination bucket");
    }
    return 0;
}

The error occurred here, and it also shows "EXC_BAD_ACCESS"

-(void)dealloc
{
    [connectionState release];
    [date release];
    [etag release]; // crash
    [server release];
    [id2 release];
    [versionId release];
    [serverSideEncryption release];
    [headers release]; // crash

    [dateFormatter release];

    [super dealloc];
}

Thanks!

Source: Stack Overflow

Your Answer

Feedback
Your Name / email address
Feedback as
Your feedback
close
Quickly sign in with:

Create a FATALWEB account here:

First name:

Last name:

E-mail address:

Join Fatalweb

Already have a fatalweb account? Log in here