【问题标题】:iOS Uploading AVCapture Recorded Video to Server via AFNetworking 3.0 MultipartiOS 通过 AFNetworking 3.0 Multipart 将 AVCapture 录制的视频上传到服务器
【发布时间】:2016-11-03 07:25:12
【问题描述】:

我使用 AVCapture 彻底录制视频并将该视频 url 传递给我有 AVPlayer 的下一个控制器,它可以很好地播放视频并使用此代码在服务器上上传视频,当我调用此表单 viewDidAppear 时它工作正常但是当我打电话时缺少按钮操作请求正文中的这个,意味着服务器没有收到视频。任何人都知道我错过了什么或做错了什么。

-(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];


}

【问题讨论】:

  • 你的控制台说什么?当您按下按钮时,您是否检查过 _videoUrl 中是否存在文件?
  • 使用相同的 url 我正在 AVPlayer 中播放视频。
  • @otusweb 感谢您为我指明正确的方向。我跟踪问题,actullay 我正在使用单例类将临时视频保存到照片库。在其中,当我在 viewDidLoad 中调用 videoUploading 方法时,我使用了 completionBlock,该块处于活动状态并且视频在 URL 处退出,当我从按钮操作调用该块时时间块执行已完成,临时视频已从该 URL 中删除。
  • 很高兴我能帮忙:-)

标签: ios objective-c video afnetworking-3 avcapture


【解决方案1】:

改变这个:

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

【讨论】:

  • 你尝试过使用 NSDATA 上传吗?
  • 没有尝试使用 NSData 让我尝试并告诉你。
猜你喜欢
  • 1970-01-01
  • 2014-03-07
  • 1970-01-01
  • 2021-07-07
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多