1

我必须在 ios 中创建将视频上传到服务器的应用程序。我正在使用下面给出的上传视频的代码。此代码上传小视频并且运行良好,但无法上传 5 mb 以上的视频。

- (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 中上传大型视频文件有什么建议吗?

4

1 回答 1

0

NSURLConnection很老了,看看NSURLSession它的代表和块。这是一些教程,如何从一个迁移到另一个

于 2013-11-07T10:22:58.110 回答