2016-11-03 4 views
0

AVCapture를 사용하여 비디오를 철저히 녹화하고 비디오를 재생하고이 코드를 사용하여 서버에 비디오를 업로드 할 때 AVPlayer가있는 다음 컨트롤러로 비디오 URL을 전달합니다. 이 양식 viewDidAppear 잘 작동하지만 단추 몸 요청 요청 본문이 누락 된, 서버가 video.Any 사람이 무엇을 놓치지 또는 잘못된 일을 생각하지 못했습니다.iOS AVCapture 녹화 된 비디오를 AFNetworking 3.0 Multipart를 통해 서버에 업로드합니다.

-(void)uploadVideotoServer{ 



[userInfoDict setValue:[[NSUserDefaults standardUserDefaults] valueForKey:@"latitude"] forKey:@"latitude"]; 
[userInfoDict setValue:[[NSUserDefaults standardUserDefaults] valueForKey:@"longitude"] forKey:@"longitude"]; 

    _request = [[AFHTTPRequestSerializer serializer] multipartFormRequestWithMethod:@"POST" URLString:@"serverURL" parameters:userInfoDict constructingBodyWithBlock:^(id<AFMultipartFormData> formData){ 
    NSLog(@"\n\n requrst time out is%f\n\n", [_request timeoutInterval]); 

    [formData appendPartWithFileURL:testPAth name:@"video" fileName:@"myvideo.mov" mimeType:@"video" error:nil]; 

    NSLog(@"\n video yp upload %@\n\n",_videoUrl); 
    // got video video url like this 
    //file:///private/var/mobile/Containers/Data/Application/3870C653-DAF9-484C-B51E-F30D8239E6F3/tmp/output7.mov 
} error:nil]; 

[self.view addSubview:_playerProgress]; 


AFURLSessionManager *manager = [[AFURLSessionManager alloc] initWithSessionConfiguration:[NSURLSessionConfiguration defaultSessionConfiguration]]; 

_uploadTask = [manager 
       uploadTaskWithStreamedRequest:_request 
       progress:^(NSProgress * _Nonnull uploadProgress) 

       { 

        dispatch_async(dispatch_get_main_queue(), ^{ 

        [_playerProgress setProgress:uploadProgress.fractionCompleted]; 

         NSLog(@"\nuploading video vlaues %f\n",uploadProgress.fractionCompleted); 

        }); 
       } 

       completionHandler:^(NSURLResponse * _Nonnull response, id _Nullable responseObject, NSError * _Nullable error) { 
        if (error) { 
         NSLog(@"Error: %@", error); 


         [_playerProgress setHidden:YES]; 

        } else 
        { 

         NSLog(@"%@ ", response); 


         [_playerProgress setHidden:YES]; 

         NSLog(@"\n\n REsponse Form Server %@\n\n",responseObject); 

        } 
       } 


       ]; 

[_uploadTask resume]; 


} 
+0

콘솔은 무엇을 말하는가? _videoUrl에 파일이있는 것을 확인 했습니까? – otusweb

+0

동일한 URL을 사용하여 AVPlayer에서 비디오를 재생 중입니다. –

+0

@otusweb는 올바른 방향으로 나를 가리켜 주셔서 감사합니다. 내가 문제를 추적, actullay 사진 라이브러리에 임시 비디오를 저장하는 데 singleton 클래스를 사용하고 있습니다. 내가 completionBlock을 사용했을 때 viewDidLoad에서 videoUploading 메서드를 호출하면 해당 블록이 활성화되고 비디오가 URL에서 종료되고 해당 버튼에 대한 작업에서 호출 할 때 시간 블록 실행이 완료되고 해당 URL에서 임시 비디오가 제거되었습니다. –

답변

0

변경이 :

[formData appendPartWithFileURL:testPAth name:@"video" fileName:@"myvideo.mov" mimeType:@"video/quicktime" error:nil]; 
+0

나는 이것을 시도하지만 작동하지 않았다. –

+0

NSDATA를 사용하여 업로드를 시도 했습니까? – KKRocks

+0

NSData로 시도하지 않았으므로 알려주겠습니다. –