How to upload saved video to a remote server captured using cordovaCapture?

I use the captureVideo method for cordovaCapture as follows:

$cordovaCapture.captureVideo(options)
  .then(function(videoData) {
    var file_path = videoData[0].fullPath;
   // upload to server
});

I get the file path as

File: / storage / .... mp4

How to upload this file to a remote server, can I access this file directly through the controller or do I have to process the URL from it?

I am using the Ionic framework.

Any help would be greatly appreciated.

+4
source share
1 answer

It is pretty simple. This will only work in ionic FW

you must first install the file transfer plugin. if not use this command:

cordova plugin add org.apache.cordova.file-transfer

suppose http://www.samplewebsite.com/upload . this is a hyperlink to your server.

example.controller("ExampleController", function($scope, $cordovaFileTransfer) {

    $scope.upload = function() {
        var options = {
            fileKey: "avatar",
            fileName: "filename.mp4",
            chunkedMode: false,
            mimeType: "video/mp4"
        };
        $cordovaFileTransfer.upload("http://www.samplewebsite.com/upload", "file:/storage/....mp4", options).then(function(result) {
            console.log("SUCCESS: " + JSON.stringify(result.response));
        }, function(err) {
            console.log("ERROR: " + JSON.stringify(err));
        }, function (progress) {
            // constant progress updates
        });
    }

});

<button class="button" ng-click="upload()">video upload</button>

. .

+5

Source: https://habr.com/ru/post/1598873/


All Articles