I am getting the NSURLErrorDomain Code=-1021 "request body stream exhausted"
NSLocalizedDescription=request body stream exhausted, NSUnderlyingError=0x2088c080 "request body stream exhausted"}
This error is generated when uploading multiple big size images I am using AFNetworking and tried to search for a fix online, but didn't succeed
NSDictionary *clientUniqueId = [NSDictionary dictionaryWithObject:NSLocalizedString(uniqueDrId, nil) forKey:@"clientUniqueId"];
NSMutableURLRequest *request = [client multipartFormRequestWithMethod:@"POST"
path:pendingUpload.urlPath
parameters:clientUniqueId
constructingBodyWithBlock:^(id<AFMultipartFormData> formData)
{
[formData appendPartWithFormData:[pendingUpload dataRecordData] name:@"dr"];
NSArray *attachments = pendingUpload.attachments;
if (attachments != nil) {
for (Attachment *attachment in attachments) {
[formData appendPartWithFileData:attachment.data
name:attachment.key
fileName:attachment.filename
mimeType:attachment.contentType];
}
}
}];
I was experiencing this issue also and didn't have any luck with the
throttleBandwithWithPacketSize
method. I believe in my case it was an authentication challenge issue.What I finally did was switch to the URLSession connection method in AFNetworking 2.0 and that seemed to solve it for me. Here is the code I ended up using:
As described in the AFNetworking FAQ: