Tuesday, 27 August 2013

Calc Content-MD5 in AFNetworking

Calc Content-MD5 in AFNetworking

I'm attempting to calculate the content-md5 header for the payload of a
multipart-form upload:
NSURLRequest *request = [client multipartFormRequestWithMethod:@"POST"
path:@"/upload"
parameters:nil constructingBodyWithBlock: ^(id <AFMultipartFormData>
formData) {
[formData appendPartWithFileData:imageData name:@"avatar"
fileName:@"avatar.png"
mimeType:@"image/png"];
}];
I tried to read the HTTPBodyStream :
if ([request HTTPBodyStream]) {
NSInteger result;
uint8_t buffer[1024];
while((result = [[request HTTPBodyStream] read:buffer maxLength:1024])
!= 0)
{
if(result > 0) {
[data appendString:[NSString stringWithUTF8String:(char
*)buffer]];
} else {...}
}
But I end up in an infinite loop. Is there a way to do this?

No comments:

Post a Comment