问题
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