You should use uploadTaskWithRequest: request fromFile: only. The trick here is that you need to write the contents of a multi-page request to a temp file, and then load that file.
AFHTTPRequestSerializer: requestWithMultipartFormRequest: writingStreamContentsToFile: completeHandler:.
. https://github.com/AFNetworking/AFNetworking/issues/1874 - Lansing
, :
NSString * filePath = [NSTemporaryDirectory() stringByAppendingPathComponent: TEMP_DATA_FILE]; [data writeToFile: filePath atomically: YES]; NSURL * filepathURL = [NSURL fileURLWithPath: filePath];
NSString *tempFile = [NSTemporaryDirectory() stringByAppendingPathComponent:TEMP_MULTI_PART_REQUEST_FILE];
NSURL *filePathtemp = [NSURL fileURLWithPath:tempFile];
AFHTTPRequestSerializer *serializer = [AFHTTPRequestSerializer serializer];
NSError *error = nil;
NSMutableURLRequest *request =
[serializer multipartFormRequestWithMethod:@"POST" URLString:AppendStrings(HOST_FOR_SERVICE_ACCESS, SERVICE_FOR_MULTIPART_UPLOAD)
parameters:parameters
constructingBodyWithBlock:^(id<AFMultipartFormData> formData)
{[formData appendPartWithFileURL:filepathURL name:@"data" error:nil];}
error:&error ];
__block NSProgress *progress = nil;
[serializer requestWithMultipartFormRequest:request writingStreamContentsToFile:filePathtemp completionHandler:^(NSError *error) {
NSURLSessionUploadTask *uploadTask = [self.sessionManager uploadTaskWithRequest:request fromFile:filePathtemp progress:&progress completionHandler:^(NSURLResponse *response, id responseObject, NSError *error) {}];
[uploadTask resume];
.