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

无人久伴 提交于 2019-12-06 05:35:12

问题


I am using the captureVideo method of 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, will I be able to access this file directly through my controller or will I have to process a url out of it?

I am using the Ionic framework.

Any help would be much appreciated.


回答1:


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

first you must be installed file transfer plugin. if not use this command:

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

assume http://www.samplewebsite.com/upload. is your server hyperlink.

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
        });
    }

});

after all you need to call this function like this

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

Its working. I have done many times.



来源:https://stackoverflow.com/questions/31537966/how-to-upload-saved-video-to-a-remote-server-captured-using-cordovacapture

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!