iphone – 如何在文件夹中保存视频然后上传到服务器

iphone – 如何在文件夹中保存视频然后上传到服务器,第1张

概述参见英文答案 > How to record a video clip in ipad app and store it in documents folder                                    3个 我正在录制来自ipad应用程序的视频,我希望该视频可以保存在文档文件夹中,或者直接我们可以将其上传到服务器.我在文档中存储音频文件但是如何保存视频文件.我使用以下 参见英文答案 > How to record a video clip in ipad app and store it in documents folder                                    3个
我正在录制来自ipad应用程序的视频,我希望该视频可以保存在文档文件夹中,或者直接我们可以将其上传到服务器.我在文档中存储音频文件但是如何保存视频文件.我使用以下代码进行录制视频.

谢谢.

UIImagePickerController *picker = [[UIImagePickerController alloc] init];  picker.delegate = self;  if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera])  {    NSArray *mediaTypes = [NSArray arrayWithObject:(Nsstring*)kUTTypeMovIE];    picker.mediaTypes = mediaTypes ;    picker.sourceType = UIImagePickerControllerSourceTypeCamera;    picker.cameraCaptureMode = UIImagePickerControllerCameraCaptureModeVIDeo ;    [self presentModalVIEwController:picker animated:NO];    [picker release];}  else    {UIAlertVIEw *alt=[[UIAlertVIEw alloc]initWithTitle:@"Error" message:@" Camera Facility is not available with this Device" delegate:self cancelbuttonTitle:@"OK" otherbuttonTitles:nil,nil];    [alt show];    [alt release];    }
解决方法 试试这个,我用当前的Date-Time存储它::

-(voID)imagePickerController:(UIImagePickerController*)picker dIDFinishPickingMediawithInfo:(NSDictionary*)info{    [self dismissVIEwControllerAnimated:NO completion:nil];    Nsstring *type = [info objectForKey:UIImagePickerControllerMediaType];    if ([type isEqualToString:(Nsstring *)kUTTypeVIDeo] || [type isEqualToString:(Nsstring *)kUTTypeMovIE])    {        vIDeoURL = [info objectForKey:UIImagePickerControllerMediaURL];        NSLog(@"found a vIDeo");        // Code To give name to vIDeo and store to documentDirectory //        vIDeoData = [[NSData dataWithContentsOfURL:vIDeoURL] retain];        NSArray *paths = NSSearchPathForDirectorIEsInDomains(NSdocumentDirectory,NSUserDomainMask,YES);        Nsstring *documentsDirectory = [paths objectAtIndex:0];        NSDateFormatter *dateFormat = [[[NSDateFormatter alloc] init] autorelease];        [dateFormat setDateFormat:@"dd-MM-yyyy||HH:mm:SS"];        NSDate *Now = [[[NSDate alloc] init] autorelease];        theDate = [dateFormat stringFromDate:Now];        Nsstring *dataPath = [documentsDirectory stringByAppendingPathComponent:@"Default Album"];        if (![[NSfileManager defaultManager] fileExistsAtPath:dataPath])           [[NSfileManager defaultManager] createDirectoryAtPath:dataPath withIntermediateDirectorIEs:NO attributes:nil error:nil];        Nsstring *vIDeopath= [[[Nsstring alloc] initWithString:[Nsstring stringWithFormat:@"%@/%@.mov",documentsDirectory,theDate]] autorelease];        BOol success = [vIDeoData writetofile:vIDeopath atomically:NO];        NSLog(@"Successs:::: %@",success ? @"YES" : @"NO");        NSLog(@"vIDeo path --> %@",vIDeopath);    }}

视频上传::

vIDeoData来自vIDeoData = [[NSData dataWithContentsOfURL:vIDeoURL] retain];

- (voID)uploadVIDeo{    NSData *imageData = vIDeoData;    Nsstring *urlString=[Nsstring stringWithFormat:@"%s",UploadVIDeoService];    NSLog(@"url=== %@",urlString);    request = [[[NSMutableURLRequest alloc] init] autorelease];    [request setURL:[NSURL URLWithString:urlString]];    [request sethttpMethod:@"POST"];    Nsstring *boundary = @"---------------------------14737809831466499882746641449";    Nsstring *ContentType = [Nsstring stringWithFormat:@"multipart/form-data; boundary=%@",boundary];    [request addValue:ContentType forhttpheaderFIEld: @"Content-Type"];    /*  body of the post */    NSMutableData *body = [NSMutableData data];    [body appendData:[[Nsstring stringWithFormat:@"\r\n--%@\r\n",boundary] dataUsingEnCoding:NSUTF8StringEnCoding]];    //VIDeo name with Date-Time    NSDateFormatter *dateFormat=[[NSDateFormatter alloc]init];    [dateFormat setDateFormat:@"yyyy-MM-dd-hh:mm:ssa"];    Nsstring *currDate = [dateFormat stringFromDate:[NSDate date]];    Nsstring *str = [Nsstring stringWithFormat:@"Content-disposition: form-data; name=\"file\"; filename=\"vIDeo-%@.mov\"\r\n",currDate];    NSLog(@"String name::  %@",str);    [dateFormat release];    [body appendData:[[Nsstring stringWithString:str] dataUsingEnCoding:NSUTF8StringEnCoding]];    [body appendData:[@"Content-Type: application/octet-stream\r\n\r\n" dataUsingEnCoding:NSUTF8StringEnCoding]];    [body appendData:[NSData dataWithData:imageData]];    [body appendData:[[Nsstring stringWithFormat:@"\r\n--%@--\r\n",boundary] dataUsingEnCoding:NSUTF8StringEnCoding]];    [request sethttpBody:body];    NSData *returnData = [NSURLConnection sendSynchronousRequest:request returningResponse:nil error:nil];    Nsstring *returnString = [[Nsstring alloc] initWithData:returnData enCoding:NSUTF8StringEnCoding];    NSLog(@"result from webservice:::--> %@",returnString);    [returnString release];}

希望,它会帮助你.

谢谢.

总结

以上是内存溢出为你收集整理的iphone – 如何在文件夹中保存视频然后上传到服务器全部内容,希望文章能够帮你解决iphone – 如何在文件夹中保存视频然后上传到服务器所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/web/1086029.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-27
下一篇 2022-05-27

发表评论

登录后才能评论

评论列表(0条)

保存