2016-11-03 7 views
0

AVCaptureを使用してビデオを徹底的に記録し、ビデオURLを次のコントローラーに渡します。ビデオを再生し、このコードを使用してサーバーにビデオをアップロードするAVPlayerこのフォーム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私は正しい方向に向いてくれてありがとう。私は問題をトレースし、私は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で試してみませんでした。 –

関連する問題