Amazon S3: Copy an Object Using Multipart Copy
See more S3 - REST Examples
Copy an object inside a general purpose bucket without downloading it. Initiate a destination upload, issue UploadPartCopy ranges, and complete it with the exact returned ETags. Requires source read and destination write permissions, plus applicable KMS permissions. HTTP 200 copy/completion bodies are checked for embedded errors.
The example uses 1,000,000,000-byte parts and supports objects larger than 5 MiB through 10,000,000,000,000 bytes (10 TB), with up to 10,000 parts. Decimal-string offset construction avoids int64 and 32-bit overflow. This is an example limit, not S3’s maximum object size; larger objects require larger parts. Only the final part may be below 5 MiB.
A source version is pinned when returned by HEAD, and every part uses the original ETag condition. Choose a distinct destination key; completing can replace that key or create a new version. Metadata and tags are not automatically inherited by multipart initiation; set the desired destination metadata, content type and encryption there. The source remains unchanged.
The saved s3-multipart.json can be used with the existing abort example after a failure. Completion XML is saved only after all copy parts succeed. Do not restart into the same state file blindly; an uncertain initiation/completion needs inspection. This example does not implement selective resume, and incomplete parts incur charges until completed or aborted.
For general purpose S3 buckets, using regional HTTPS endpoints and AWS Signature Version 4. Directory buckets (S3 Express), access points, Outposts, and other AWS partitions need their own endpoint/authentication rules. Use a bucket name without dots for these virtual-hosted TLS examples; see the path-style example for dotted names.
Provide current IAM credentials in a private qa_data/aws/s3.json file with string fields access_key, secret_key, and session_token for temporary credentials. Prefer short-lived role credentials. This file is explicitly loaded; these examples do not discover profiles or refresh credentials. Keep it outside public content and source control. The session token is included in the signed request. TLS certificate verification is enabled on the Socket used by Rest.
Transport success and HTTP success are different. Keep full diagnostics private; signed requests and presigned URLs can contain credentials or grant access. For retryable reads use bounded backoff with jitter. Before retrying a write with an uncertain outcome, check the resource state. Keep keys, upload IDs, version IDs, ETags, and large sizes as strings.
Chilkat Objective-C Downloads
#import <CkoStringBuilder.h>
#import <CkoJsonObject.h>
#import <NSString.h>
#import <CkoAuthAws.h>
#import <CkoRest.h>
#import <CkoSocket.h>
#import <CkoXml.h>
#import <CkoFileAccess.h>
BOOL success = NO;
// StringBuilder compares text by value in every generated language.
CkoStringBuilder *textCompare = [[CkoStringBuilder alloc] init];
// Assumes Chilkat is unlocked. See Global Unlock Sample.
success = NO;
// Private configuration, not a file in public web content or source control.
// Load current IAM credentials authorized for the S3 operation.
CkoJsonObject *credentials = [[CkoJsonObject alloc] init];
credentials.Strict = YES;
success = [credentials LoadFile: @"qa_data/aws/s3.json"];
if (success != YES) {
NSLog(@"%@",@"Could not load private AWS credentials.");
return;
}
[textCompare Clear];
[textCompare SetString: [credentials StringOf: @"access_key"]];
BOOL sameText1 = [textCompare ContentsEqual: @"" caseSensitive: YES];
if (([[credentials JsonTypeOf: @"access_key"] intValue] != 1) || (sameText1 == YES)) {
NSLog(@"%@",@"Missing or invalid access_key.");
return;
}
[textCompare Clear];
[textCompare SetString: [credentials StringOf: @"secret_key"]];
BOOL sameText2 = [textCompare ContentsEqual: @"" caseSensitive: YES];
if (([[credentials JsonTypeOf: @"secret_key"] intValue] != 1) || (sameText2 == YES)) {
NSLog(@"%@",@"Missing or invalid secret_key.");
return;
}
// General purpose bucket in the commercial AWS partition.
NSString *region = @"us-west-2";
NSString *bucketName = @"amzn-s3-demo-bucket";
CkoStringBuilder *endpoint = [[CkoStringBuilder alloc] init];
success = [endpoint Append: bucketName];
if (success != YES) {
NSLog(@"%@",@"Could not build text.");
return;
}
success = [endpoint Append: @"."];
if (success != YES) {
NSLog(@"%@",@"Could not build text.");
return;
}
success = [endpoint Append: @"s3."];
if (success != YES) {
NSLog(@"%@",@"Could not build text.");
return;
}
success = [endpoint Append: region];
if (success != YES) {
NSLog(@"%@",@"Could not build text.");
return;
}
success = [endpoint Append: @".amazonaws.com"];
if (success != YES) {
NSLog(@"%@",@"Could not build text.");
return;
}
CkoAuthAws *aws = [[CkoAuthAws alloc] init];
aws.AccessKey = [credentials StringOf: @"access_key"];
aws.SecretKey = [credentials StringOf: @"secret_key"];
aws.Region = region;
aws.ServiceName = @"s3";
aws.SignatureVersion = [NSNumber numberWithInt:4];
CkoRest *rest = [[CkoRest alloc] init];
rest.ConnectTimeoutMs = [NSNumber numberWithInt:20000];
rest.IdleTimeoutMs = [NSNumber numberWithInt:60000];
success = [rest SetAuthAws: aws];
if (success != YES) {
NSLog(@"%@",@"Could not configure AWS signing.");
return;
}
// Temporary credentials require this token in every signed query.
// Keep request URLs private. Do not clear this parameter between requests.
if ([credentials HasMember: @"session_token"] == YES) {
if ([[credentials JsonTypeOf: @"session_token"] intValue] != 1) {
NSLog(@"%@",@"session_token must be a string.");
return;
}
[textCompare Clear];
[textCompare SetString: [credentials StringOf: @"session_token"]];
BOOL sameText3 = [textCompare ContentsEqual: @"" caseSensitive: YES];
if (sameText3 != YES) {
success = [rest AddQueryParam: @"X-Amz-Security-Token" value: [credentials StringOf: @"session_token"]];
if (success != YES) {
NSLog(@"%@",@"Could not prepare the request.");
return;
}
}
}
// Connect to the SAME hostname used for TLS verification and request signing.
CkoSocket *connection = [[CkoSocket alloc] init];
connection.RequireSslCertVerify = YES;
connection.MaxReadIdleMs = [NSNumber numberWithInt:60000];
connection.MaxSendIdleMs = [NSNumber numberWithInt:60000];
success = [connection Connect: [endpoint GetAsString] port: [NSNumber numberWithInt: 443] ssl: YES maxWaitMs: [NSNumber numberWithInt: 20000]];
if (success != YES) {
NSLog(@"%@",@"TLS connection failed; inspect diagnostics privately.");
return;
}
success = [rest UseConnection: connection autoReconnect: YES];
if (success != YES) {
NSLog(@"%@",@"Could not attach the TLS connection.");
return;
}
CkoXml *xml = [[CkoXml alloc] init];
xml.Strict = YES;
// Supply an unencoded object key, not a URL. Preserve slashes in the key.
NSString *objectKey = @"documents/source.bin";
CkoStringBuilder *objectPath = [[CkoStringBuilder alloc] init];
success = [objectPath Append: objectKey];
if (success != YES) {
NSLog(@"%@",@"Could not build text.");
return;
}
success = [objectPath Encode: @"url_rfc3986" charset: @"utf-8"];
if (success != YES) {
NSLog(@"%@",@"Could not encode the object key.");
return;
}
int restoredSlashes = [[objectPath Replace: @"%2F" replacement: @"/"] intValue];
success = [objectPath Prepend: @"/"];
if (success != YES) {
NSLog(@"%@",@"Could not prepare the request.");
return;
}
success = [rest SendReqNoBody: @"HEAD" uriPath: [objectPath GetAsString]];
if (success != YES) {
NSLog(@"%@",@"Could not send HEAD request.");
return;
}
int statusCode = [[rest ReadResponseHeader] intValue];
if (statusCode < 0) {
NSLog(@"%@",@"Could not read the response header.");
return;
}
if (statusCode != 200) {
NSLog(@"%@",@"HEAD did not return HTTP 200. A 403 is not proof that an object is missing.");
return;
}
// HEAD has no response body; do not call a body-reading method.
NSString *sourceEtag = [rest ResponseHdrByName: @"ETag"];
[textCompare Clear];
[textCompare SetString: sourceEtag];
BOOL sameText4 = [textCompare ContentsEqual: @"" caseSensitive: YES];
if ((rest.LastMethodSuccess != YES) || (sameText4 == YES)) {
NSLog(@"%@",@"Missing response header: ETag");
return;
}
NSString *sourceSize = [rest ResponseHdrByName: @"Content-Length"];
[textCompare Clear];
[textCompare SetString: sourceSize];
BOOL sameText5 = [textCompare ContentsEqual: @"" caseSensitive: YES];
if ((rest.LastMethodSuccess != YES) || (sameText5 == YES)) {
NSLog(@"%@",@"Missing response header: Content-Length");
return;
}
NSString *sourceVersion = [rest ResponseHdrByName: @"x-amz-version-id"];
if (rest.LastMethodSuccess != YES) {
sourceVersion = @"";
}
// Split a decimal size into billions and a remainder. No large integer type.
CkoStringBuilder *sizeText = [[CkoStringBuilder alloc] init];
CkoStringBuilder *digits = [[CkoStringBuilder alloc] init];
CkoStringBuilder *piece = [[CkoStringBuilder alloc] init];
success = [sizeText Append: sourceSize];
if (success != YES) {
NSLog(@"%@",@"Could not build text.");
return;
}
success = [digits Append: @"0123456789"];
if (success != YES) {
NSLog(@"%@",@"Could not build text.");
return;
}
if (([sizeText.Length intValue] < 1) || ([sizeText.Length intValue] > 14)) {
NSLog(@"%@",@"Invalid source length for this example.");
return;
}
int position = 0;
while ((position < [sizeText.Length intValue])) {
NSString *digit = [sizeText GetRange: [NSNumber numberWithInt: position] numChars: [NSNumber numberWithInt: 1] removeFlag: NO];
if ([digits Contains: digit caseSensitive: YES] != YES) {
NSLog(@"%@",@"Source length is not decimal.");
return;
}
position = position + 1;
}
int fullBillions = 0;
int tailBytes = 0;
if ([sizeText.Length intValue] > 9) {
success = [piece SetString: [sizeText GetRange: [NSNumber numberWithInt: 0] numChars: [NSNumber numberWithInt: ([sizeText.Length intValue] - 9)] removeFlag: NO]];
if (success != YES) {
NSLog(@"%@",@"Could not prepare the request.");
return;
}
fullBillions = [piece.IntValue intValue];
success = [piece SetString: [sizeText GetRange: [NSNumber numberWithInt: ([sizeText.Length intValue] - 9)] numChars: [NSNumber numberWithInt: 9] removeFlag: NO]];
if (success != YES) {
NSLog(@"%@",@"Could not prepare the request.");
return;
}
tailBytes = [piece.IntValue intValue];
}
else {
tailBytes = [sizeText.IntValue intValue];
}
int numParts = fullBillions;
if (tailBytes > 0) {
numParts = numParts + 1;
}
if ((numParts < 1) || (numParts > 10000)) {
NSLog(@"%@",@"This example supports objects through 10 TB using 1 GB parts.");
return;
}
if ((fullBillions == 0) && (tailBytes <= 5242880)) {
NSLog(@"%@",@"Use CopyObject for sources of 5 MiB or less; ranged copy requires a larger source.");
return;
}
CkoFileAccess *files = [[CkoFileAccess alloc] init];
if ([files FileExists: @"s3-multipart.json"] == YES) {
NSLog(@"%@",@"A multipart state file already exists; finish or abort that upload first.");
return;
}
CkoStringBuilder *copySource = [[CkoStringBuilder alloc] init];
success = [copySource Append: @"/"];
if (success != YES) {
NSLog(@"%@",@"Could not build text.");
return;
}
success = [copySource Append: bucketName];
if (success != YES) {
NSLog(@"%@",@"Could not build text.");
return;
}
success = [copySource Append: [objectPath GetAsString]];
if (success != YES) {
NSLog(@"%@",@"Could not build text.");
return;
}
[textCompare Clear];
[textCompare SetString: sourceVersion];
BOOL sameText6 = [textCompare ContentsEqual: @"" caseSensitive: YES];
if (sameText6 != YES) {
CkoStringBuilder *encodedVersion = [[CkoStringBuilder alloc] init];
success = [encodedVersion Append: sourceVersion];
if (success != YES) {
NSLog(@"%@",@"Could not build text.");
return;
}
success = [encodedVersion Encode: @"url_rfc3986" charset: @"utf-8"];
if (success != YES) {
NSLog(@"%@",@"Could not prepare the request.");
return;
}
success = [copySource Append: @"?versionId="];
if (success != YES) {
NSLog(@"%@",@"Could not build text.");
return;
}
success = [copySource Append: [encodedVersion GetAsString]];
if (success != YES) {
NSLog(@"%@",@"Could not build text.");
return;
}
}
// Destination is a DIFFERENT key in this bucket. Existing destination is replaced.
NSString *destinationKey = @"documents/copy.bin";
[textCompare Clear];
[textCompare SetString: destinationKey];
BOOL sameText7 = [textCompare ContentsEqual: objectKey caseSensitive: YES];
if (sameText7 == YES) {
NSLog(@"%@",@"Choose a destination key different from the source.");
return;
}
success = [objectPath SetString: destinationKey];
if (success != YES) {
NSLog(@"%@",@"Could not prepare the request.");
return;
}
success = [objectPath Encode: @"url_rfc3986" charset: @"utf-8"];
if (success != YES) {
NSLog(@"%@",@"Could not prepare the request.");
return;
}
int destinationSlashes = [[objectPath Replace: @"%2F" replacement: @"/"] intValue];
success = [objectPath Prepend: @"/"];
if (success != YES) {
NSLog(@"%@",@"Could not prepare the request.");
return;
}
success = [rest AddQueryParam: @"uploads" value: @""];
if (success != YES) {
NSLog(@"%@",@"Could not prepare the request.");
return;
}
success = [rest AddHeader: @"Content-Type" value: @"application/octet-stream"];
if (success != YES) {
NSLog(@"%@",@"Could not prepare the request.");
return;
}
NSString *responseBody = [rest FullRequestNoBody: @"POST" uriPath: [objectPath GetAsString]];
if (rest.LastMethodSuccess != YES) {
NSLog(@"%@",@"Request did not complete; inspect diagnostics privately.");
return;
}
if ([rest.ResponseStatusCode intValue] != 200) {
NSLog(@"%@%d",@"S3 HTTP status: ",[rest.ResponseStatusCode intValue]);
success = [xml LoadXml: responseBody];
[textCompare Clear];
[textCompare SetString: xml.Tag];
BOOL sameText8 = [textCompare ContentsEqual: @"Error" caseSensitive: YES];
if ((success == YES) && (sameText8 == YES)) {
NSLog(@"%@%@",@"S3 error code: ",[xml GetChildContent: @"Code"]);
}
// Keep signed headers, credentials, URLs, and full diagnostics private.
// A timeout may leave a write's outcome uncertain. Check before retrying.
return;
}
success = [xml LoadXml: responseBody];
if (success != YES) {
NSLog(@"%@",@"Expected well-formed XML.");
return;
}
[textCompare Clear];
[textCompare SetString: xml.Tag];
BOOL sameText9 = [textCompare ContentsEqual: @"InitiateMultipartUploadResult" caseSensitive: YES];
if (sameText9 != YES) {
NSLog(@"%@",@"Unexpected S3 response element; this is not a successful result.");
return;
}
[textCompare Clear];
[textCompare SetString: [xml GetChildContent: @"UploadId"]];
BOOL sameText10 = [textCompare ContentsEqual: @"" caseSensitive: YES];
if (([xml HasChildWithTag: @"UploadId"] != YES) || (sameText10 == YES)) {
NSLog(@"%@",@"Missing response field: UploadId");
return;
}
NSString *uploadId = [xml GetChildContent: @"UploadId"];
CkoJsonObject *state = [[CkoJsonObject alloc] init];
success = [state UpdateString: @"bucket" value: bucketName];
if (success != YES) {
NSLog(@"%@",@"Could not build saved state.");
return;
}
success = [state UpdateString: @"region" value: region];
if (success != YES) {
NSLog(@"%@",@"Could not build saved state.");
return;
}
success = [state UpdateString: @"key" value: destinationKey];
if (success != YES) {
NSLog(@"%@",@"Could not build saved state.");
return;
}
success = [state UpdateString: @"upload_id" value: uploadId];
if (success != YES) {
NSLog(@"%@",@"Could not build saved state.");
return;
}
success = [state UpdateString: @"source_key" value: objectKey];
if (success != YES) {
NSLog(@"%@",@"Could not build saved state.");
return;
}
success = [state UpdateString: @"source_etag" value: sourceEtag];
if (success != YES) {
NSLog(@"%@",@"Could not build saved state.");
return;
}
success = [state UpdateString: @"source_size" value: sourceSize];
if (success != YES) {
NSLog(@"%@",@"Could not build saved state.");
return;
}
success = [state WriteFile: @"s3-multipart.json"];
if (success != YES) {
NSLog(@"%@",@"Upload initiated but saving state failed; recover the upload ID or list unfinished uploads.");
return;
}
success = [rest RemoveQueryParam: @"uploads"];
if (success != YES) {
NSLog(@"%@",@"Could not prepare the request.");
return;
}
success = [rest RemoveHeader: @"Content-Type"];
if (success != YES) {
NSLog(@"%@",@"Could not prepare the request.");
return;
}
success = [rest AddQueryParam: @"uploadId" value: uploadId];
if (success != YES) {
NSLog(@"%@",@"Could not prepare the request.");
return;
}
success = [rest AddHeader: @"x-amz-copy-source" value: [copySource GetAsString]];
if (success != YES) {
NSLog(@"%@",@"Could not prepare the request.");
return;
}
success = [rest AddHeader: @"x-amz-copy-source-if-match" value: sourceEtag];
if (success != YES) {
NSLog(@"%@",@"Could not prepare the request.");
return;
}
CkoXml *parts = [[CkoXml alloc] init];
parts.Tag = @"CompleteMultipartUpload";
CkoStringBuilder *range = [[CkoStringBuilder alloc] init];
CkoStringBuilder *ending = [[CkoStringBuilder alloc] init];
CkoStringBuilder *number = [[CkoStringBuilder alloc] init];
int partNumber = 1;
while ((partNumber <= numParts)) {
[range Clear];
[ending Clear];
[number Clear];
success = [range Append: @"bytes="];
if (success != YES) {
NSLog(@"%@",@"Could not build text.");
return;
}
if (partNumber == 1) {
success = [range Append: @"0"];
if (success != YES) {
NSLog(@"%@",@"Could not build text.");
return;
}
}
else {
success = [range AppendInt: [NSNumber numberWithInt: (partNumber - 1)]];
if (success != YES) {
NSLog(@"%@",@"Could not prepare the request.");
return;
}
success = [range Append: @"000000000"];
if (success != YES) {
NSLog(@"%@",@"Could not build text.");
return;
}
}
success = [range Append: @"-"];
if (success != YES) {
NSLog(@"%@",@"Could not build text.");
return;
}
if (partNumber <= fullBillions) {
if (partNumber > 1) {
success = [ending AppendInt: [NSNumber numberWithInt: (partNumber - 1)]];
if (success != YES) {
NSLog(@"%@",@"Could not prepare the request.");
return;
}
}
success = [ending Append: @"999999999"];
if (success != YES) {
NSLog(@"%@",@"Could not build text.");
return;
}
}
else {
success = [ending AppendInt: [NSNumber numberWithInt: (tailBytes - 1)]];
if (success != YES) {
NSLog(@"%@",@"Could not prepare the request.");
return;
}
if (fullBillions > 0) {
while (([ending.Length intValue] < 9)) {
success = [ending Prepend: @"0"];
if (success != YES) {
NSLog(@"%@",@"Could not prepare the request.");
return;
}
}
success = [number AppendInt: [NSNumber numberWithInt: fullBillions]];
if (success != YES) {
NSLog(@"%@",@"Could not prepare the request.");
return;
}
success = [ending Prepend: [number GetAsString]];
if (success != YES) {
NSLog(@"%@",@"Could not prepare the request.");
return;
}
}
}
success = [range Append: [ending GetAsString]];
if (success != YES) {
NSLog(@"%@",@"Could not build text.");
return;
}
[number Clear];
success = [number AppendInt: [NSNumber numberWithInt: partNumber]];
if (success != YES) {
NSLog(@"%@",@"Could not prepare the request.");
return;
}
if (partNumber > 1) {
success = [rest RemoveQueryParam: @"partNumber"];
if (success != YES) {
NSLog(@"%@",@"Could not prepare the request.");
return;
}
success = [rest RemoveHeader: @"x-amz-copy-source-range"];
if (success != YES) {
NSLog(@"%@",@"Could not prepare the request.");
return;
}
}
success = [rest AddQueryParam: @"partNumber" value: [number GetAsString]];
if (success != YES) {
NSLog(@"%@",@"Could not prepare the request.");
return;
}
success = [rest AddHeader: @"x-amz-copy-source-range" value: [range GetAsString]];
if (success != YES) {
NSLog(@"%@",@"Could not prepare the request.");
return;
}
responseBody = [rest FullRequestNoBody: @"PUT" uriPath: [objectPath GetAsString]];
if (rest.LastMethodSuccess != YES) {
NSLog(@"%@",@"Request did not complete; inspect diagnostics privately.");
return;
}
if ([rest.ResponseStatusCode intValue] != 200) {
NSLog(@"%@%d",@"S3 HTTP status: ",[rest.ResponseStatusCode intValue]);
success = [xml LoadXml: responseBody];
[textCompare Clear];
[textCompare SetString: xml.Tag];
BOOL sameText11 = [textCompare ContentsEqual: @"Error" caseSensitive: YES];
if ((success == YES) && (sameText11 == YES)) {
NSLog(@"%@%@",@"S3 error code: ",[xml GetChildContent: @"Code"]);
}
// Keep signed headers, credentials, URLs, and full diagnostics private.
// A timeout may leave a write's outcome uncertain. Check before retrying.
return;
}
success = [xml LoadXml: responseBody];
if (success != YES) {
NSLog(@"%@",@"Expected well-formed XML.");
return;
}
[textCompare Clear];
[textCompare SetString: xml.Tag];
BOOL sameText12 = [textCompare ContentsEqual: @"CopyPartResult" caseSensitive: YES];
if (sameText12 != YES) {
NSLog(@"%@",@"Unexpected S3 response element; this is not a successful result.");
return;
}
[textCompare Clear];
[textCompare SetString: [xml GetChildContent: @"ETag"]];
BOOL sameText13 = [textCompare ContentsEqual: @"" caseSensitive: YES];
if (([xml HasChildWithTag: @"ETag"] != YES) || (sameText13 == YES)) {
NSLog(@"%@",@"Missing response field: ETag");
return;
}
parts.I = [NSNumber numberWithInt: (partNumber - 1)];
[parts UpdateChildContentInt: @"Part[i]|PartNumber" value: [NSNumber numberWithInt: partNumber]];
[parts UpdateChildContent: @"Part[i]|ETag" value: [xml GetChildContent: @"ETag"]];
NSLog(@"%@%d",@"Copied part: ",partNumber);
partNumber = partNumber + 1;
}
success = [state UpdateString: @"completion_xml" value: [parts GetXml]];
if (success != YES) {
NSLog(@"%@",@"Could not build saved state.");
return;
}
success = [state WriteFile: @"s3-multipart.json"];
if (success != YES) {
NSLog(@"%@",@"Parts copied but completion state could not be saved.");
return;
}
success = [rest RemoveHeader: @"x-amz-copy-source"];
if (success != YES) {
NSLog(@"%@",@"Could not prepare the request.");
return;
}
success = [rest RemoveHeader: @"x-amz-copy-source-if-match"];
if (success != YES) {
NSLog(@"%@",@"Could not prepare the request.");
return;
}
success = [rest RemoveHeader: @"x-amz-copy-source-range"];
if (success != YES) {
NSLog(@"%@",@"Could not prepare the request.");
return;
}
success = [rest RemoveQueryParam: @"partNumber"];
if (success != YES) {
NSLog(@"%@",@"Could not prepare the request.");
return;
}
success = [rest AddHeader: @"Content-Type" value: @"application/xml"];
if (success != YES) {
NSLog(@"%@",@"Could not prepare the request.");
return;
}
responseBody = [rest FullRequestString: @"POST" uriPath: [objectPath GetAsString] bodyText: [parts GetXml]];
if (rest.LastMethodSuccess != YES) {
NSLog(@"%@",@"Request did not complete; inspect diagnostics privately.");
return;
}
if ([rest.ResponseStatusCode intValue] != 200) {
NSLog(@"%@%d",@"S3 HTTP status: ",[rest.ResponseStatusCode intValue]);
success = [xml LoadXml: responseBody];
[textCompare Clear];
[textCompare SetString: xml.Tag];
BOOL sameText14 = [textCompare ContentsEqual: @"Error" caseSensitive: YES];
if ((success == YES) && (sameText14 == YES)) {
NSLog(@"%@%@",@"S3 error code: ",[xml GetChildContent: @"Code"]);
}
// Keep signed headers, credentials, URLs, and full diagnostics private.
// A timeout may leave a write's outcome uncertain. Check before retrying.
return;
}
success = [xml LoadXml: responseBody];
if (success != YES) {
NSLog(@"%@",@"Expected well-formed XML.");
return;
}
[textCompare Clear];
[textCompare SetString: xml.Tag];
BOOL sameText15 = [textCompare ContentsEqual: @"CompleteMultipartUploadResult" caseSensitive: YES];
if (sameText15 != YES) {
NSLog(@"%@",@"Unexpected S3 response element; this is not a successful result.");
return;
}
[textCompare Clear];
[textCompare SetString: [xml GetChildContent: @"ETag"]];
BOOL sameText16 = [textCompare ContentsEqual: @"" caseSensitive: YES];
if (([xml HasChildWithTag: @"ETag"] != YES) || (sameText16 == YES)) {
NSLog(@"%@",@"Missing response field: ETag");
return;
}
NSLog(@"%@",@"Multipart copy completed; source was not deleted.");
// Archive s3-multipart.json after confirming the destination.