The multipart upload of an image worked fine with AFNetwrking 1.0 and I need to upgrade to 3.0. However, the request parameters and the body disappear. It seems to be in AFURLRequestSerialization.m the statement:
[self.request setHTTPBodyStream:self.bodyStream]
even though the parts and body are present in self.bodyStream
. There doesn't seem be an error returned from setHTTPBodyStream
.
This is the code:
AFHTTPRequestSerializer *requestSerializer = [AFHTTPRequestSerializer serializer];
NSURLSessionConfiguration *configuration = [NSURLSessionConfiguration defaultSessionConfiguration];
AFURLSessionManager *manager = [[AFURLSessionManager alloc] initWithSessionConfiguration:configuration];
manager.responseSerializer = [AFHTTPResponseSerializer serializer];
manager.securityPolicy.allowInvalidCertificates = YES; // not recommended for production
manager.securityPolicy.validatesDomainName = NO;
[requestSerializer setValue:@"multipart/form-data" forHTTPHeaderField:@"content-type"];
NSMutableURLRequest *request = [requestSerializer multipartFormRequestWithMethod:@"POST" URLString: ServerPath
parameters:sendDictionary constructingBodyWithBlock:^(id<AFMultipartFormData> formData) {
[formData appendPartWithFileData: imageData name:@"file" fileName:@"temp.jpeg" mimeType:@"image/jpeg"];
} error:nil];
[request setTimeoutInterval:20000];
NSURLSessionUploadTask *uploadTask;
NSLog(@"Request body %@", [[NSString alloc] initWithData:[request HTTPBody] encoding:NSUTF8StringEncoding]); NSLog(@"Request HTTP Headers: %@", request.allHTTPHeaderFields); NSLog(@"%@", [request HTTPBody]);
uploadTask = [manager