S3 Http: Download an Object Byte Range
See more S3 - HTTP Examples
Uses Chilkat.Http with Amazon S3 general purpose buckets and Signature Version 4. These examples do not cover directory buckets/S3 Express, access-point ARNs, Outposts, or other specialized endpoints. They target the commercial AWS partition; other partitions need their documented endpoint suffix.
Load private qa_data/aws/s3.json containing nonempty string fields access_key and secret_key, plus session_token for temporary credentials. Prefer short-lived role credentials. These samples do not discover AWS profiles or refresh credentials. Set the bucket's actual region and replace sample bucket names and object keys. TLS certificate verification is explicitly enabled. Keep detailed HTTP diagnostics private because they can contain credentials or presigned URLs.
Uses explicit signed Http requests to preserve query parameters, conditional headers, and full responses. The included SigV4 block signs the exact path, sorted encoded query and headers used by this example; it is not a general-purpose HTTP signing library. Keep the clock accurate and do not change signed data after signing. Code requires Chilkat 11.6.0 or later; locally tested with 11.8.0.
HEAD selects the current object and captures its ETag and version ID when available. GET requests bytes=0-1048575 using If-Match and that version. Requires HTTP 206, exact Content-Range/Content-Length, matching ETag, and the actual 1 MiB file length. HTTP 200 (Range ignored), 412, and 416 never promote output. Use an object at least 1 MiB in size and unused output paths.
Ranges are inclusive object offsets. This example downloads a range of an S3 object directly; it is not a standalone Glacier retrieval job. A whole-object checksum is not a checksum of a range. Requires s3:GetObject/s3:GetObjectVersion and applicable KMS permissions; archived objects must already be restored.
Chilkat Objective-C Downloads
#import <CkoStringBuilder.h>
#import <CkoJsonObject.h>
#import <CkoHttp.h>
#import <NSString.h>
#import <CkoHttpResponse.h>
#import <CkoCrypt2.h>
#import <CkoDateTime.h>
#import <CkoXml.h>
#import <CkoFileAccess.h>
#import <CkoMime.h>
BOOL success = NO;
CkoStringBuilder *stringCompare = [[CkoStringBuilder alloc] init];
// This example requires the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
// Load private credentials; never put access keys or session tokens in source.
CkoJsonObject *credentials = [[CkoJsonObject alloc] init];
credentials.Strict = YES;
success = [credentials LoadFile: @"qa_data/aws/s3.json"];
if (success != YES) {
NSLog(@"%@",@"Could not load private S3 credentials.");
return;
}
[stringCompare SetString: [credentials StringOf: @"access_key"]];
BOOL stringMatch1 = [stringCompare ContentsEqual: @"" caseSensitive: YES];
if (([[credentials JsonTypeOf: @"access_key"] intValue] != 1) || (stringMatch1 == YES)) {
NSLog(@"%@",@"Missing or invalid access_key.");
return;
}
[stringCompare SetString: [credentials StringOf: @"secret_key"]];
BOOL stringMatch2 = [stringCompare ContentsEqual: @"" caseSensitive: YES];
if (([[credentials JsonTypeOf: @"secret_key"] intValue] != 1) || (stringMatch2 == YES)) {
NSLog(@"%@",@"Missing or invalid secret_key.");
return;
}
CkoHttp *http = [[CkoHttp alloc] init];
http.AwsAccessKey = [credentials StringOf: @"access_key"];
http.AwsSecretKey = [credentials StringOf: @"secret_key"];
if ([credentials HasMember: @"session_token"] == YES) {
[stringCompare SetString: [credentials StringOf: @"session_token"]];
BOOL stringMatch3 = [stringCompare ContentsEqual: @"" caseSensitive: YES];
if (([[credentials JsonTypeOf: @"session_token"] intValue] != 1) || (stringMatch3 == YES)) {
NSLog(@"%@",@"session_token must be a nonempty string when supplied.");
return;
}
http.AwsSessionToken = [credentials StringOf: @"session_token"];
}
// Current Chilkat uses SigV4 by default. Do not select deprecated SigV2.
// Set the actual bucket region, not the caller's location.
NSString *region = @"us-west-2";
http.AwsRegion = region;
CkoStringBuilder *endpoint = [[CkoStringBuilder alloc] init];
[endpoint Append: @"s3."];
[endpoint Append: region];
[endpoint Append: @".amazonaws.com"];
http.AwsEndpoint = [endpoint GetAsString];
http.RequireSslCertVerify = YES;
http.FollowRedirects = NO;
// A region redirect is not success. Correct the endpoint and signing region.
NSString *bucketName = @"your-bucket-name";
NSString *objectKey = @"examples/archive.bin";
CkoHttpResponse *response = [[CkoHttpResponse alloc] init];
CkoCrypt2 *signer = [[CkoCrypt2 alloc] init];
signer.Charset = @"utf-8";
signer.HashAlgorithm = @"sha256";
signer.EncodingMode = @"hexlower";
signer.MacAlgorithm = @"hmac";
CkoDateTime *now = [[CkoDateTime alloc] init];
CkoStringBuilder *timestamp = [[CkoStringBuilder alloc] init];
CkoStringBuilder *canonical = [[CkoStringBuilder alloc] init];
CkoStringBuilder *canonicalHeaders = [[CkoStringBuilder alloc] init];
CkoStringBuilder *signedHeaders = [[CkoStringBuilder alloc] init];
CkoStringBuilder *scope = [[CkoStringBuilder alloc] init];
CkoStringBuilder *stringToSign = [[CkoStringBuilder alloc] init];
CkoStringBuilder *signingKey = [[CkoStringBuilder alloc] init];
CkoStringBuilder *authorization = [[CkoStringBuilder alloc] init];
CkoStringBuilder *url = [[CkoStringBuilder alloc] init];
CkoStringBuilder *query = [[CkoStringBuilder alloc] init];
CkoStringBuilder *number = [[CkoStringBuilder alloc] init];
CkoStringBuilder *host = [[CkoStringBuilder alloc] init];
CkoStringBuilder *uri = [[CkoStringBuilder alloc] init];
CkoXml *xml = [[CkoXml alloc] init];
NSString *amzDate = 0;
NSString *dateStamp = 0;
NSString *payloadHash = 0;
NSString *canonicalHash = 0;
NSString *derivedKey = 0;
NSString *signature = 0;
int replaceCount;
[host Append: bucketName];
[host Append: @"."];
[host Append: [endpoint GetAsString]];
// Encode the original key exactly once, preserving S3 path separators.
[uri SetString: [http UrlEncode: objectKey]];
replaceCount = [[uri ReplaceNoCase: @"%2f" replacement: @"/"] intValue];
if (([uri StartsWith: @"/" caseSensitive: YES] == YES) || ([uri Contains: @"/../" caseSensitive: YES] == YES) || ([uri Contains: @"/./" caseSensitive: YES] == YES)) {
NSLog(@"%@",@"Use a key without a leading slash or dot path segments for these examples.");
return;
}
[uri Prepend: @"/"];
NSString *versionId = @"";
NSString *etag = 0;
NSString *expectedSize = 0;
NSString *returnedVersion = 0;
CkoFileAccess *files = [[CkoFileAccess alloc] init];
NSString *finalPath = @"qa_output/s3-download.bin";
NSString *partialPath = @"qa_output/s3-download.bin.part";
if (([files FileExists: finalPath] == YES) || ([files FileExists: partialPath] == YES)) {
NSLog(@"%@",@"Choose unused output paths.");
return;
}
[query Clear];
[stringCompare SetString: versionId];
BOOL stringMatch4 = [stringCompare ContentsEqual: @"" caseSensitive: YES];
if (stringMatch4 != YES) {
if ([query.Length intValue] > 0) {
[query Append: @"&"];
}
[query Append: @"versionId="];
[query Append: [http UrlEncode: versionId]];
}
[http ClearHeaders];
success = [now SetFromCurrentSystemTime];
if (success != YES) {
NSLog(@"%@",@"Could not read system time.");
return;
}
[timestamp SetString: [now GetAsTimestamp: NO]];
replaceCount = [[timestamp Replace: @"-" replacement: @""] intValue];
replaceCount = [[timestamp Replace: @":" replacement: @""] intValue];
amzDate = [timestamp GetAsString];
dateStamp = [timestamp GetRange: [NSNumber numberWithInt: 0] numChars: [NSNumber numberWithInt: 8] removeFlag: NO];
payloadHash = [signer HashStringENC: @""];
if (signer.LastMethodSuccess != YES) {
NSLog(@"%@",@"Could not hash payload.");
return;
}
[canonicalHeaders Clear];
[signedHeaders Clear];
if ([signedHeaders.Length intValue] > 0) {
[signedHeaders Append: @";"];
}
[signedHeaders Append: @"host"];
[canonicalHeaders Append: @"host:"];
[canonicalHeaders Append: [host GetAsString]];
[canonicalHeaders Append: @"\n"];
[http SetRequestHeader: @"host" value: [host GetAsString]];
if ([signedHeaders.Length intValue] > 0) {
[signedHeaders Append: @";"];
}
[signedHeaders Append: @"x-amz-content-sha256"];
[canonicalHeaders Append: @"x-amz-content-sha256:"];
[canonicalHeaders Append: payloadHash];
[canonicalHeaders Append: @"\n"];
[http SetRequestHeader: @"x-amz-content-sha256" value: payloadHash];
if ([signedHeaders.Length intValue] > 0) {
[signedHeaders Append: @";"];
}
[signedHeaders Append: @"x-amz-date"];
[canonicalHeaders Append: @"x-amz-date:"];
[canonicalHeaders Append: amzDate];
[canonicalHeaders Append: @"\n"];
[http SetRequestHeader: @"x-amz-date" value: amzDate];
if ([credentials HasMember: @"session_token"] == YES) {
if ([signedHeaders.Length intValue] > 0) {
[signedHeaders Append: @";"];
}
[signedHeaders Append: @"x-amz-security-token"];
[canonicalHeaders Append: @"x-amz-security-token:"];
[canonicalHeaders Append: [credentials StringOf: @"session_token"]];
[canonicalHeaders Append: @"\n"];
[http SetRequestHeader: @"x-amz-security-token" value: [credentials StringOf: @"session_token"]];
}
[canonical Clear];
[canonical Append: @"HEAD\n"];
[canonical Append: [uri GetAsString]];
[canonical Append: @"\n"];
[canonical Append: [query GetAsString]];
[canonical Append: @"\n"];
[canonical Append: [canonicalHeaders GetAsString]];
[canonical Append: @"\n"];
[canonical Append: [signedHeaders GetAsString]];
[canonical Append: @"\n"];
[canonical Append: payloadHash];
canonicalHash = [signer HashStringENC: [canonical GetAsString]];
if (signer.LastMethodSuccess != YES) {
NSLog(@"%@",@"Could not hash canonical request.");
return;
}
[scope Clear];
[scope Append: dateStamp];
[scope Append: @"/"];
[scope Append: region];
[scope Append: @"/s3/aws4_request"];
[stringToSign Clear];
[stringToSign Append: @"AWS4-HMAC-SHA256\n"];
[stringToSign Append: amzDate];
[stringToSign Append: @"\n"];
[stringToSign Append: [scope GetAsString]];
[stringToSign Append: @"\n"];
[stringToSign Append: canonicalHash];
[signingKey SetString: @"AWS4"];
[signingKey Append: [credentials StringOf: @"secret_key"]];
success = [signer SetMacKeyString: [signingKey GetAsString]];
if (success != YES) {
NSLog(@"%@",@"Could not set signing key.");
return;
}
derivedKey = [signer MacStringENC: dateStamp];
if (signer.LastMethodSuccess != YES) {
NSLog(@"%@",@"Could not derive signing key.");
return;
}
success = [signer SetMacKeyEncoded: derivedKey encoding: @"hex"];
if (success != YES) {
NSLog(@"%@",@"Could not set signing key.");
return;
}
derivedKey = [signer MacStringENC: region];
if (signer.LastMethodSuccess != YES) {
NSLog(@"%@",@"Could not derive signing key.");
return;
}
success = [signer SetMacKeyEncoded: derivedKey encoding: @"hex"];
if (success != YES) {
NSLog(@"%@",@"Could not set signing key.");
return;
}
derivedKey = [signer MacStringENC: @"s3"];
if (signer.LastMethodSuccess != YES) {
NSLog(@"%@",@"Could not derive signing key.");
return;
}
success = [signer SetMacKeyEncoded: derivedKey encoding: @"hex"];
if (success != YES) {
NSLog(@"%@",@"Could not set signing key.");
return;
}
derivedKey = [signer MacStringENC: @"aws4_request"];
if (signer.LastMethodSuccess != YES) {
NSLog(@"%@",@"Could not derive signing key.");
return;
}
success = [signer SetMacKeyEncoded: derivedKey encoding: @"hex"];
if (success != YES) {
NSLog(@"%@",@"Could not set signing key.");
return;
}
signature = [signer MacStringENC: [stringToSign GetAsString]];
if (signer.LastMethodSuccess != YES) {
NSLog(@"%@",@"Could not sign request.");
return;
}
[authorization Clear];
[authorization Append: @"AWS4-HMAC-SHA256 Credential="];
[authorization Append: [credentials StringOf: @"access_key"]];
[authorization Append: @"/"];
[authorization Append: [scope GetAsString]];
[authorization Append: @", SignedHeaders="];
[authorization Append: [signedHeaders GetAsString]];
[authorization Append: @", Signature="];
[authorization Append: signature];
[http SetRequestHeader: @"Authorization" value: [authorization GetAsString]];
[url SetString: @"https://"];
[url Append: [host GetAsString]];
[url Append: [uri GetAsString]];
if ([query.Length intValue] > 0) {
[url Append: @"?"];
[url Append: [query GetAsString]];
}
success = [http HttpNoBody: @"HEAD" url: [url GetAsString] response: response];
if ((success != YES) || ([response.StatusCode intValue] != 200)) {
NSLog(@"%@%d",@"Request failed or returned unexpected HTTP status: ",[response.StatusCode intValue]);
// Preserve progress. Inspect full diagnostics privately; do not log secrets.
return;
}
etag = [response GetHeaderField: @"ETag"];
[stringCompare SetString: etag];
BOOL stringMatch5 = [stringCompare ContentsEqual: @"" caseSensitive: YES];
if ((response.LastMethodSuccess != YES) || (stringMatch5 == YES)) {
NSLog(@"%@",@"Missing required response header ETag.");
return;
}
expectedSize = [response GetHeaderField: @"Content-Length"];
[stringCompare SetString: expectedSize];
BOOL stringMatch6 = [stringCompare ContentsEqual: @"" caseSensitive: YES];
if ((response.LastMethodSuccess != YES) || (stringMatch6 == YES)) {
NSLog(@"%@",@"Missing required response header Content-Length.");
return;
}
returnedVersion = [response GetHeaderField: @"x-amz-version-id"];
if (response.LastMethodSuccess != YES) {
returnedVersion = @"";
}
[stringCompare SetString: versionId];
BOOL stringMatch7 = [stringCompare ContentsEqual: @"" caseSensitive: YES];
if (stringMatch7 == YES) {
versionId = returnedVersion;
}
else {
[stringCompare SetString: returnedVersion];
BOOL stringMatch8 = [stringCompare ContentsEqual: versionId caseSensitive: YES];
if (stringMatch8 != YES) {
NSLog(@"%@",@"Unexpected object version.");
return;
}
}
// Download the first 1 MiB of an object containing at least that many bytes.
[number SetString: expectedSize];
if (([number.Length intValue] < 8) && ([number.IntValue intValue] < 1048576)) {
NSLog(@"%@",@"Choose an object of at least 1 MiB for this fixed range example.");
return;
}
[query Clear];
[stringCompare SetString: versionId];
BOOL stringMatch9 = [stringCompare ContentsEqual: @"" caseSensitive: YES];
if (stringMatch9 != YES) {
if ([query.Length intValue] > 0) {
[query Append: @"&"];
}
[query Append: @"versionId="];
[query Append: [http UrlEncode: versionId]];
}
[http ClearHeaders];
success = [now SetFromCurrentSystemTime];
if (success != YES) {
NSLog(@"%@",@"Could not read system time.");
return;
}
[timestamp SetString: [now GetAsTimestamp: NO]];
replaceCount = [[timestamp Replace: @"-" replacement: @""] intValue];
replaceCount = [[timestamp Replace: @":" replacement: @""] intValue];
amzDate = [timestamp GetAsString];
dateStamp = [timestamp GetRange: [NSNumber numberWithInt: 0] numChars: [NSNumber numberWithInt: 8] removeFlag: NO];
payloadHash = [signer HashStringENC: @""];
if (signer.LastMethodSuccess != YES) {
NSLog(@"%@",@"Could not hash payload.");
return;
}
[canonicalHeaders Clear];
[signedHeaders Clear];
if ([signedHeaders.Length intValue] > 0) {
[signedHeaders Append: @";"];
}
[signedHeaders Append: @"host"];
[canonicalHeaders Append: @"host:"];
[canonicalHeaders Append: [host GetAsString]];
[canonicalHeaders Append: @"\n"];
[http SetRequestHeader: @"host" value: [host GetAsString]];
if ([signedHeaders.Length intValue] > 0) {
[signedHeaders Append: @";"];
}
[signedHeaders Append: @"if-match"];
[canonicalHeaders Append: @"if-match:"];
[canonicalHeaders Append: etag];
[canonicalHeaders Append: @"\n"];
[http SetRequestHeader: @"if-match" value: etag];
if ([signedHeaders.Length intValue] > 0) {
[signedHeaders Append: @";"];
}
[signedHeaders Append: @"range"];
[canonicalHeaders Append: @"range:"];
[canonicalHeaders Append: @"bytes=0-1048575"];
[canonicalHeaders Append: @"\n"];
[http SetRequestHeader: @"range" value: @"bytes=0-1048575"];
if ([signedHeaders.Length intValue] > 0) {
[signedHeaders Append: @";"];
}
[signedHeaders Append: @"x-amz-content-sha256"];
[canonicalHeaders Append: @"x-amz-content-sha256:"];
[canonicalHeaders Append: payloadHash];
[canonicalHeaders Append: @"\n"];
[http SetRequestHeader: @"x-amz-content-sha256" value: payloadHash];
if ([signedHeaders.Length intValue] > 0) {
[signedHeaders Append: @";"];
}
[signedHeaders Append: @"x-amz-date"];
[canonicalHeaders Append: @"x-amz-date:"];
[canonicalHeaders Append: amzDate];
[canonicalHeaders Append: @"\n"];
[http SetRequestHeader: @"x-amz-date" value: amzDate];
if ([credentials HasMember: @"session_token"] == YES) {
if ([signedHeaders.Length intValue] > 0) {
[signedHeaders Append: @";"];
}
[signedHeaders Append: @"x-amz-security-token"];
[canonicalHeaders Append: @"x-amz-security-token:"];
[canonicalHeaders Append: [credentials StringOf: @"session_token"]];
[canonicalHeaders Append: @"\n"];
[http SetRequestHeader: @"x-amz-security-token" value: [credentials StringOf: @"session_token"]];
}
[canonical Clear];
[canonical Append: @"GET\n"];
[canonical Append: [uri GetAsString]];
[canonical Append: @"\n"];
[canonical Append: [query GetAsString]];
[canonical Append: @"\n"];
[canonical Append: [canonicalHeaders GetAsString]];
[canonical Append: @"\n"];
[canonical Append: [signedHeaders GetAsString]];
[canonical Append: @"\n"];
[canonical Append: payloadHash];
canonicalHash = [signer HashStringENC: [canonical GetAsString]];
if (signer.LastMethodSuccess != YES) {
NSLog(@"%@",@"Could not hash canonical request.");
return;
}
[scope Clear];
[scope Append: dateStamp];
[scope Append: @"/"];
[scope Append: region];
[scope Append: @"/s3/aws4_request"];
[stringToSign Clear];
[stringToSign Append: @"AWS4-HMAC-SHA256\n"];
[stringToSign Append: amzDate];
[stringToSign Append: @"\n"];
[stringToSign Append: [scope GetAsString]];
[stringToSign Append: @"\n"];
[stringToSign Append: canonicalHash];
[signingKey SetString: @"AWS4"];
[signingKey Append: [credentials StringOf: @"secret_key"]];
success = [signer SetMacKeyString: [signingKey GetAsString]];
if (success != YES) {
NSLog(@"%@",@"Could not set signing key.");
return;
}
derivedKey = [signer MacStringENC: dateStamp];
if (signer.LastMethodSuccess != YES) {
NSLog(@"%@",@"Could not derive signing key.");
return;
}
success = [signer SetMacKeyEncoded: derivedKey encoding: @"hex"];
if (success != YES) {
NSLog(@"%@",@"Could not set signing key.");
return;
}
derivedKey = [signer MacStringENC: region];
if (signer.LastMethodSuccess != YES) {
NSLog(@"%@",@"Could not derive signing key.");
return;
}
success = [signer SetMacKeyEncoded: derivedKey encoding: @"hex"];
if (success != YES) {
NSLog(@"%@",@"Could not set signing key.");
return;
}
derivedKey = [signer MacStringENC: @"s3"];
if (signer.LastMethodSuccess != YES) {
NSLog(@"%@",@"Could not derive signing key.");
return;
}
success = [signer SetMacKeyEncoded: derivedKey encoding: @"hex"];
if (success != YES) {
NSLog(@"%@",@"Could not set signing key.");
return;
}
derivedKey = [signer MacStringENC: @"aws4_request"];
if (signer.LastMethodSuccess != YES) {
NSLog(@"%@",@"Could not derive signing key.");
return;
}
success = [signer SetMacKeyEncoded: derivedKey encoding: @"hex"];
if (success != YES) {
NSLog(@"%@",@"Could not set signing key.");
return;
}
signature = [signer MacStringENC: [stringToSign GetAsString]];
if (signer.LastMethodSuccess != YES) {
NSLog(@"%@",@"Could not sign request.");
return;
}
[authorization Clear];
[authorization Append: @"AWS4-HMAC-SHA256 Credential="];
[authorization Append: [credentials StringOf: @"access_key"]];
[authorization Append: @"/"];
[authorization Append: [scope GetAsString]];
[authorization Append: @", SignedHeaders="];
[authorization Append: [signedHeaders GetAsString]];
[authorization Append: @", Signature="];
[authorization Append: signature];
[http SetRequestHeader: @"Authorization" value: [authorization GetAsString]];
[url SetString: @"https://"];
[url Append: [host GetAsString]];
[url Append: [uri GetAsString]];
if ([query.Length intValue] > 0) {
[url Append: @"?"];
[url Append: [query GetAsString]];
}
success = [http Download: [url GetAsString] saveToPath: partialPath];
if ([http.LastStatus intValue] == 412) {
NSLog(@"%@",@"Object changed; range was not downloaded.");
return;
}
if ([http.LastStatus intValue] == 416) {
NSLog(@"%@",@"Requested range is not satisfiable; inspect object size and offsets.");
return;
}
if ((success != YES) || ([http.LastStatus intValue] != 206)) {
NSLog(@"%@%d",@"Request failed or returned unexpected HTTP status: ",[http.LastStatus intValue]);
// Preserve progress. Inspect full diagnostics privately; do not log secrets.
return;
}
CkoMime *received = [[CkoMime alloc] init];
success = [received LoadMime: http.LastResponseHeader];
if (success != YES) {
NSLog(@"%@",@"Could not parse download headers.");
return;
}
NSString *actualRange = 0;
NSString *actualEtag = 0;
NSString *receivedLength = 0;
CkoStringBuilder *expectedRange = [[CkoStringBuilder alloc] init];
[expectedRange Append: @"bytes 0-1048575/"];
[expectedRange Append: expectedSize];
actualRange = [received GetHeaderField: @"Content-Range"];
[stringCompare SetString: actualRange];
BOOL stringMatch10 = [stringCompare ContentsEqual: @"" caseSensitive: YES];
if ((received.LastMethodSuccess != YES) || (stringMatch10 == YES)) {
NSLog(@"%@",@"Missing download header Content-Range.");
return;
}
receivedLength = [received GetHeaderField: @"Content-Length"];
[stringCompare SetString: receivedLength];
BOOL stringMatch11 = [stringCompare ContentsEqual: @"" caseSensitive: YES];
if ((received.LastMethodSuccess != YES) || (stringMatch11 == YES)) {
NSLog(@"%@",@"Missing download header Content-Length.");
return;
}
actualEtag = [received GetHeaderField: @"ETag"];
[stringCompare SetString: actualEtag];
BOOL stringMatch12 = [stringCompare ContentsEqual: @"" caseSensitive: YES];
if ((received.LastMethodSuccess != YES) || (stringMatch12 == YES)) {
NSLog(@"%@",@"Missing download header ETag.");
return;
}
[stringCompare SetString: actualRange];
BOOL stringMatch13 = [stringCompare ContentsEqual: [expectedRange GetAsString] caseSensitive: YES];
[stringCompare SetString: receivedLength];
BOOL stringMatch14 = [stringCompare ContentsEqual: @"1048576" caseSensitive: YES];
[stringCompare SetString: actualEtag];
BOOL stringMatch15 = [stringCompare ContentsEqual: etag caseSensitive: YES];
if ((stringMatch13 != YES) || (stringMatch14 != YES) || (stringMatch15 != YES)) {
NSLog(@"%@",@"Range response does not match the requested object bytes.");
return;
}
NSString *actualSize = [files FileSizeStr: partialPath];
[stringCompare SetString: actualSize];
BOOL stringMatch16 = [stringCompare ContentsEqual: @"1048576" caseSensitive: YES];
if ((files.LastMethodSuccess != YES) || (stringMatch16 != YES)) {
NSLog(@"%@",@"Range byte count mismatch.");
return;
}
success = [files FileRename: partialPath newPath: finalPath];
if (success != YES) {
NSLog(@"%@",@"Range remains at the temporary path.");
return;
}
NSLog(@"%@",@"Range download succeeded; byte count checked.");
// A whole-object checksum cannot be used to verify this partial range.