Search code examples
androidioscordovavideocordova-plugins

cordova File Transfer plugin not uploading video to Server


  1. I'm creating an Hybrid app in which I want to upload video to server. Sometimes it uploads the video to the server but most of the time Plugin shows the uploading progress to 99% and then it gives null in success callback. Thanks in advance. :-)

    /********* OPENING CAMERA TO CPTURE VIDEO ***********/
    function make_Video()
    {
        // capture callback
        var captureSuccess = function(mediaFiles) {
    
            var i, len , video_path;
    
            if(mediaFiles.length > 0)
            {
    
                for (i = 0, len = mediaFiles.length; i < len; i += 1)
                {
                    video_path = mediaFiles[i].fullPath;
    
                    Upload_Video(video_path);
    
                }
    
            }
    
        };
    
        // capture error callback
        var captureError = function(error)
        {
          console.log('Error Code: ' + error.code);
        };
    navigator.device.capture.captureVideo(captureSuccess, captureError, { quality: 100,destinationType: Camera.DestinationType.FILE_URI });
    
    }
    
    /****************STORING VIDEO ON SERVER******************/
    function Upload_Video(video_path)
    {
        var server =  server_link; // MY SERVER LINK
        var params = {'user_id':logged_in_user_id,'action':'update_intro_video'};
    
        if (server)
        {
    
                // Specify transfer options
                $('#modal_first_line').text(0+" %"+" Uploaded");
                $('#new_modal').show();
                var options         = new FileUploadOptions();
                options.fileKey     = "user_video";
    
          options.fileName = video_path.substr(video_path.lastIndexOf('/')+1);
    
                options.mimeType    = "video/mp4";
                options.chunkedMode = false;
                options.httpMethod  = "POST";
                options.params      = params;
                // Transfer picture to server
                var ft = new FileTransfer();
    
    
     //progree bar
     ft.onprogress = function(progressEvent) {
    
    if (progressEvent.lengthComputable){  var perc = Math.floor(progressEvent.loaded / progressEvent.total * 100); $('#modal_first_line').text(perc+" %"+"
    Uploaded"); } else {$('#new_modal').hide();
           console.log("sorry! Upload Failed..."); }  };
    
                ft.upload(video_path, encodeURI(server) , function(data) {
                            $('#new_modal').hide();
                            console.log("SERVER RESPONSE: " + JSON.stringify(data));
                          },
                          function(error)
                          {
                            $('#new_modal').hide();
                            console.log("sorry! Upload Failed...");
                          }, options);
        }
    
        else{
                $('#new_modal').hide();
                console.log("sorry! Can't Upload File.");;
        }
    }
    

Solution

  • Solved.
    The Problem was at server end. Configuration was making trouble. post_max_size was set to 8Mb, so when limit of video exceeds to 8MB, server was not allowing to save the video. I increased the post_max_size to 100MB. To Increase the post_max_size , I did the following steps
    1. I Created a file .user.ini in the root directory
    2. I placed the following code inside this file
    file_uploads = O post_max_size = 100M upload_max_filesize = 200M

    Hope it will help someone.