PhoneGap视频记录并上传到服务器

时间:2017-02-22 22:04:25

标签: cordova

我对PhoneGap有一些奇怪的问题,我正在尝试从应用程序录制视频,而不是将其上传到服务器。

    app.initialize();

     $(function(){
      //capture callback
      var captureSuccess = function(mediaFiles) {
        var i, len;
        for(i = 0, len = mediaFiles.length; i < len; i += 1) {
          uploadFile(mediaFiles[i]);
        }
      };

      function uploadFile(mediaFiles) {
        var options = new FileUploadOptions();
        options.fileKey = 'file';
        options.fileName = mediaFiles.name;
        options.contentType = 'video/mp4';
        options.mimeType = mediaFiles.type;
        options.chunkedMode = true;

        var ft = new FileTransfer();
        var path = mediaFiles.fullPath;
        //var name = mediaFiles.name;

        ft.upload(path, 
          'http://domainName/~me/upload.php',
          function(result) { //success callback
            navigator.notification.alert('Path: ' + path +  ' bytesSent: ' + result.bytesSent + ' responseCode: ' + result.responseCode + ' response: ' + result.response, null, 'Upload Error');
            $("#infoMessage").html('Success!');
          },
          function(error) { //error callback
            navigator.notification.alert('Error uploading file ' + path + ', Error code: ' + error.code + ' Target: ' + error.target + ' http_status: ' + error.http_status + ' Body: ' + error.body + ' Exception: ' + error.exception.toString(), null, 'Upload Error');
            $("#infoMessage").html('Problem')
          },

          options);
      }

      // capture error callback
      var captureError = function(error) {
        navigator.notification.alert('Error code: ' + error.code, null, 'Capture Error');
      };

      //start video capture
      var accessCamera = function() {
        navigator.device.capture.captureVideo(captureSuccess, captureError, { limit:1 });
      };

                $("#cambtn").on('click', accessCamera);

服务器端正在运行,因为我应该使用Postman应用程序对其进行测试。 我从PhoneGap应用程序“成功回调”获得的响应是​​:Screenshot

服务器端脚本现在是如此基本:

$target_dir = "uploads/";
if(isset($_FILES['file'])) {
    $target_file = $target_dir . basename($_FILES["file"]["name"]);
    move_uploaded_file($_FILES['file']['tmp_name'], $target_file);
}
print_r($_FILES); //This line returns empty array when request is send by the application but it returns array with data when I test it with Postman. 
die();

问题是由chunkedMode选项引起的。它必须设置为false。

0 个答案:

没有答案