上传大文件video到服务器在ios
我必须创build应用程序上传video到服务器在ios。 我正在使用下面给出的上传video的代码。 此代码上传小video并且很好地工作,但是5 MB以上的video无法上传。
- (void)uploadvideo { NSString *strurl=[NSString stringWithFormat:@"%@",appDele.DRUPAL_SERVICES_URL]; NSString *url=[[NSString alloc]initWithFormat:@"video_upload.php?user_id=%@&node_id=%@",appDele.UserId,appDele.strProductId]; NSString *urlString =[NSString stringWithFormat:@"%@%@",strurl,url] ; NSLog(@"%@",urlString); NSString *encodedString = [urlString stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]; // setting up the request object now NSMutableURLRequest *request = [[[NSMutableURLRequest alloc] init] autorelease]; [request setURL:[NSURL URLWithString:encodedString]]; [request setHTTPMethod:@"POST"]; //[request setTimeoutInterval:10000]; // NSInputStream *videoStream = [[[NSInputStream alloc] initWithData:data1] autorelease]; // [request setHTTPBodyStream:videoStream]; NSString *boundary = [NSString stringWithFormat:@"---------------------------14737809831466499882746641449"]; NSString *contentType = [NSString stringWithFormat:@"multipart/form-data; boundary=%@",boundary]; [request addValue:contentType forHTTPHeaderField: @"Content-Type"]; /* now lets create the body of the post */ NSMutableData *body = [NSMutableData data]; [body appendData:[[NSString stringWithFormat:@"\r\n--%@\r\n",boundary] dataUsingEncoding:NSUTF8StringEncoding]]; [body appendData:[[NSString stringWithFormat:@"Content-Disposition: form-data; name=\"filename\"; filename=\"New.mp4\"\r\n"] dataUsingEncoding:NSUTF8StringEncoding]]; // NSLog(@"%@New.jpg",appDelegate.MemberId); [body appendData:[[NSString stringWithFormat:@"Content-Type: application/octet-stream\r\n\r\n"] dataUsingEncoding:NSUTF8StringEncoding]]; // [body appendData:data1.length]; [body appendData:[NSData dataWithData:data1]]; [body appendData:[[NSString stringWithFormat:@"\r\n--%@--\r\n",boundary] dataUsingEncoding:NSUTF8StringEncoding]]; // setting the body of the post to the reqeust [request setHTTPBody:body]; // now lets make the connection to the web NSData *returnData = [NSURLConnection sendSynchronousRequest:request returningResponse:nil error:nil]; NSString *returnString = [[NSString alloc] initWithData:returnData encoding:NSUTF8StringEncoding]; NSLog(@"%@",returnString); }
任何关于如何在iOS上传大video文件的build议?
NSURLConnection
是相当古老的,看看它的委托和块NSURLSession
。 这里有一些教程,如何从一个迁移到另一个 。