I want to upload a large video from iPhone to a web server. I tried with below code. It's working for small files but when I try to upload large file it gets crashed.
Code:
NSMutableURLRequest *request = [NSMutableURLRequest
requestWithURL:[NSURL URLWithString:@"https://XXXXXXXXXXXXXXXX/submit.php"]];
NSData *webData = [NSData dataWithContentsOfURL:movieUrl];
NSString *postLength = [NSString stringWithFormat:@"%d", [webData length]];
NSString *contentType = [NSString stringWithFormat:@"multipart/form-data; boundary=%@",boundary];
---- added some HTTP headers here ----
[request setHTTPMethod:@"POST"];
[request setValue:postLength forHTTPHeaderField:@"Content-Length"];
[request addValue:contentType forHTTPHeaderField: @"Content-Type"];
NSMutableData *postbody = [NSMutableData data];
[postbody appendData:[NSData dataWithData:webData]];
[request setHTTPBody:postbody];
NSURLConnection *connection = [[NSURLConnection alloc] initWithRequest:request delegate:self];
After research I got an idea as , this will be possible if I send large file in chunk of data. solution1 , solution2.
I also gone through Stream Programming apple doc. But don't know where to define server NSURL. After writing data into output stream how to send to the server.
If someone can point me to any working code then i will be able to understatnd it better.
How to do that? Have any idea?