Request checksum from Amazon S3 on iOS

I have developed an iOS app that can upload larger videos to Amazon S3 server

For this I used:

  • 1 Amazon API V1
  • 2 NSURLSession to download video to support background download.

I have included an MD5 checksum in my input request for validation after uploading the file to the Amazon server.

 NSString *md5 = [FileHash md5HashOfFileAtPath:[url path]];

    NSMutableData *commandToSend= [[NSMutableData alloc] init];
    unsigned char whole_byte;
    char byte_chars[3] = {'\0','\0','\0'};
    int i;
    for (i=0; i < [md5 length]/2; i++) {
        byte_chars[0] = [md5 characterAtIndex:i*2];
        byte_chars[1] = [md5 characterAtIndex:i*2+1];
        whole_byte = strtol(byte_chars, NULL, 16);
        [commandToSend appendBytes:&whole_byte length:1];
    }


    s3PutObjectRequest.cannedACL = [S3CannedACL publicRead];
        s3PutObjectRequest.endpoint = s3Client.endpoint;
        s3PutObjectRequest.contentType = fileMIMEType([url absoluteString]);

        NSMutableDictionary *dict = [[NSMutableDictionary alloc] init];
        [dict setValue:[NSString stringWithFormat:@"%d",footage.footageId] forKey:@"x-amz-meta-footageId"];
        [dict setValue:[NSString stringWithFormat:@"%d",footage.clipDuration]  forKey:@"x-amz-meta-duration"];
        s3PutObjectRequest.metadata =dict;
        [s3PutObjectRequest configureURLRequest];
         s3PutObjectRequest.contentMD5 = base64EncodedString;


        NSMutableURLRequest *request = [s3Client signS3Request:s3PutObjectRequest];
        NSMutableURLRequest *request2 = [[NSMutableURLRequest alloc]initWithURL:request.URL];
        [request2 setAllHTTPHeaderFields:[request allHTTPHeaderFields]];
        [request2 setValue:nil forHTTPHeaderField:@"Content-Length"];

    [request2 setValue:base64EncodedString forHTTPHeaderField:@"Content-MD5"];

      

Now I want to verify the checksum after the file has been uploaded to the server. I need to know what the Amazon API is, I can get the checksum after uploading to the server.

I read the article below and it says we can measure the checksum for data integrity.

What object gives the checksum after downloading the file?

Refresh

The eTag S3PutObjectResponse function will give you the md5 hash of the uploaded file, but now it gives me an error when I try to print the value

"ErrorCode: BadDigest, Message: The MD5 content you specified does not match what we received.

+3


source to share





All Articles