我尝试使用Apache Cordova Plugin cordova-plugin-media-capture捕获视频。如何将此视频发送到我的服务器并存储?
这是关于如何开始捕捉视频的官方示例:
// capture callback
var captureSuccess = function(mediaFiles) {
var i, path, len;
for (i = 0, len = mediaFiles.length; i < len; i += 1) {
path = mediaFiles[i].fullPath;
// do something interesting with the file
}
};
// capture error callback
var captureError = function(error) {
navigator.notification.alert('Error code: ' + error.code, null, 'Capture Error');
};
// start video capture
navigator.device.capture.captureVideo(captureSuccess, captureError, {limit:2, duration: 10});
但是如何将视频发送到我的服务器来存储呢? 我有什么要传递给我的ajax代码?
// capture callback
var captureSuccess = function(mediaFiles)
{
var i, path, len;
for (i = 0, len = mediaFiles.length; i < len; i += 1)
{
path = mediaFiles[i].fullPath;
$.ajax
(
"ajax.php",
{
type: "POST",
data: { path: path } //This will just send the path to the server
}
);
}
};
答案 0 :(得分:1)
最好使用此功能。
<select ng-model="selectedCategory">
<option ng-repeat="cat in categories" value="{{cat.value}}">
{{cat.text}}
</option>
</select>
<div ng-repeat="product in products | filter: product.category == selectedCategory">
function uploadFile(mediaFile) {
var ft = new FileTransfer(),
path = mediaFile.fullPath,
name = mediaFile.name;
var options = new FileUploadOptions();
options.mimeType = "video/mpeg";
options.fileName = name;
options.chunkedMode = true;
ft.upload(path,
"**Your WebService Url Goes Here**",
function(result) {
console.log('Upload success: ' + result.responseCode);
console.log(result.bytesSent + ' bytes sent');
},
function(error) {
console.log('Error uploading file ' + path + ': ' + error.code);
},
options);
}
。
喜欢以下。
Call this function where you are getting your File Path
编辑1
注意: uploadFile(mediaFiles[i]);
Make sure you added all below plugins in your project.