从iOS中的Amazon S3请求校验和

我开发了一个iOS应用程序,可以将更大的video上传到Amazon S3服务器

为了做到这一点,我使用了:

  • 1 Amazon V1 API
  • 2 NSURLSession上传video以支持后台上传。

我已将MD5校验和集成到我的put请求中,以便在文件上传到Amazon服务器后进行validation。

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"]; 

现在我想在文件上传到服务器后validation校验和。 我需要知道在上传到服务器后我可以获得校验和的Amazon API是什么。

我也读过下面的文章,它说我们可以测量数据完整性的校验和。

哪个对象在文件上传后给出校验和?

更新

S3PutObjectResponse eTag函数将为您提供上传文件的md5哈希值,但现在当我尝试打印值时它会给我一个错误

“ErrorCode:BadDigest,消息:您指定的Content-MD5与我们收到的内容不匹配。”