Upload videos with objective c

后端 未结 2 2014
太阳男子
太阳男子 2021-01-03 16:27

I am to build a really complicated (at least to me) app now. The basic app is as follows:

A tab bar app with two tabs, one for local videos and the other for streami

相关标签:
2条回答
  • 2021-01-03 17:10
    - (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
        {
        NSURL *urlvideo = [info objectForKey:UIImagePickerControllerMediaURL];
    
    
        urlvideo contains the URL of that video file that has to be uploaded. Then convert the url into NSString type because setFile method requires NSString as a parameter
    
        NSString *urlString=[urlvideo path];
    
        NSLog(@"urlString=%@",urlString);
        NSString *str = [NSString stringWithFormat:@"path of server"];
        NSURL *url = [NSURL URLWithString:[str stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
        ASIFormDataRequest *request = [ASIFormDataRequest requestWithURL:url];
        [request setFile:urlString forKey:@"key foruploadingFile"];
        [request setRequestMethod:@"POST"];
        [request setDelegate:self];
        [request startSynchronous];
        NSLog(@"responseStatusCode %i",[request responseStatusCode]);
        NSLog(@"responseStatusCode %@",[request responseString]);
        }
    

    Hope this code will save your couple of hours.

    0 讨论(0)
  • 2021-01-03 17:19

    Using AFNetworking:

    NSURL *url = [NSURL URLWithString:@"http://api-base-url.com"];
    AFHTTPClient *httpClient = [[AFHTTPClient alloc] initWithBaseURL:url];
    NSData *imageData = UIImageJPEGRepresentation([UIImage imageNamed:@"avatar.jpg"], 0.5);
    NSMutableURLRequest *request = [httpClient multipartFormRequestWithMethod:@"POST" path:@"/upload" parameters:nil constructingBodyWithBlock: ^(id <AFMultipartFormData>formData) {
        [formData appendPartWithFileData:imageData name:@"avatar" fileName:@"avatar.jpg" mimeType:@"image/jpeg"];
    }];
    
    0 讨论(0)
提交回复
热议问题