将大文件视频上传到ios中的服务器 [英] Upload large file video to server in ios

查看:46
本文介绍了将大文件视频上传到ios中的服务器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我必须创建用于将视频上传到ios中的服务器的应用程序.我正在使用下面提供的代码上传视频.这段代码可以上传小型视频,并且效果很好,但是5 mb以上的视频无法上传.

I have to create application for upload video to server in ios. I am using code for upload video which is given below. This code upload small video and working nicely but above 5 mb video can't upload .

- (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中上传大型视频文件的任何建议?

Any suggestion on how to upload large video file in ios?

推荐答案

NSURLConnection 很老,请看一下 NSURLSession 及其委托和代码块.这里有一些教程,介绍如何从一个迁移到另一个

NSURLConnection is quite old, take a look at NSURLSession with it's delegates and blocks. Here's some tutorial, how to migrate from one to another.

这篇关于将大文件视频上传到ios中的服务器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆