I have a problem with http PUT request and request body as stream from file.
No matter what the size of the file i get error "NSURLErrorDomain -1021 request body stream exhausted"
I know i can override this problem by implementing the method:
-(NSInputStream*)connection:(NSURLConnection *)connection needNewBodyStream:(NSURLRequest *)request
but this approach is not good as it will upload the whole file again, and 40 MB of file turns out to be 80 Mb of data transfer.
if i take the same file as NSData and set the request body it works fine.
I tried sending the request Async and sync same result in both.
Here is my code, simple and similar to example from Apple:
NSURL *url = [NSURL URLWithString:[self concatenatedURLWithPath:path]];
NSMutableURLRequest *req = [[NSMutableURLRequest alloc] initWithURL:url];
[req setHTTPMethod:@"PUT"];
[req setCachePolicy:NSURLRequestReloadIgnoringLocalCacheData];
[request setTimeoutInterval:DEFAULT_TIMEOUT];
[req setValue:_contentType forHTTPHeaderField:@"Content-Type"];
NSInputStream *fileStream = [NSInputStream inputStreamWithFileAtPath:_dataStreamLocation];
[req setHTTPBodyStream:fileStream];
_connection = [[NSURLConnection connectionWithRequest:req delegate:self] retain];
Am i doing something wrong? Am i missing something?