Upload large video using chunks via http post

I want to upload a great video from iPhone to a web server. I tried with the code below. It works for small files, but when I try to download a large file, it breaks.

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 researching, I got an idea, as it will be possible if I send a large file to a piece of data. solution1 , solution2 .

I also looked at the apple programming document. But I donโ€™t know where to define the NSURL server. After writing data to the output stream, how to send the server.

If someone can point me to any working code, then I can better understand it.

How to do it? Any ideas?

+6
source share

Source: https://habr.com/ru/post/944865/


All Articles