Yes I tried the above but its not working. Here are the steps I have taken so far :
I installed the Cordova fileUpload service and duplicated the FileUploadHelper js file (calling it FileVideoUploadHelper)and modify it for my video upload service. Then
1.when a user clicks the record a video button the following script is executed
var captureSuccess = function(mediaFiles) {
var i, path, len;
for (i = 0, len = mediaFiles.length; i < len; i += 1) {
path = mediaFiles.fullPath;
//alert(path);
// do something interesting with the file
Apperyio.storage.VideoStore.set(path);
}
};
// 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:1});
2.when a user clicks the upload video button the video is uploaded to the files database as shown below
3.Then on the viewing page the following mapping is executed on page show
However nothing is displayed on the app
Here is a copy of the FileVideoUploadHelper js file I use to upload the video
Appery.FileVideoUploadHelper = Appery.createClass(null, {
Code: Select all
init : function(requestOptions) {
this.__requestOptions = $.extend({}, requestOptions);
},
process : function(settings) {
settings.beforeSend(settings);
if (this.__requestOptions.echo) {
settings.success(this.__requestOptions.echo);
} else {
uploadVideo(settings.data.image_uri, settings.data.request_options, settings.data.name, settings);
}
}
});
function uploadVideo (path, reqOptions, name, settings) {
Code: Select all
function win(result) {
settings.success({'response':JSON.parse(result.response)});
settings.complete('success');
//alert('Upload successful. Code = ' + result.responseCode + '\n Response = ' + result.response + '\n Sent = ' + result.bytesSent);
}
function fail(error) {
settings.error(null, null, error.source);
settings.complete('error');
alert('An error has occurred: Code = ' + error.code + '\n + Upload error source ' + error.source + '\n Upload error target ' + error.target);
}
var imageType = path.substr(path.lastIndexOf('.')+1);
var options = $.extend(new FileUploadOptions(), reqOptions);
if(name) {
options.fileName = name + imageType;
options.fileKey= name + imageType;
} else {
options.fileName = path.substr(path.lastIndexOf('/')+1);
options.fileKey = path.substr(path.lastIndexOf('/')+1);
}
options.mimeType=(imageType == 'mp3')?'video/mp3':'video/mp3';
var ft = new FileTransfer();
ft.upload(path, encodeURI(FileUpload_settings.database_url+"/files"), win, fail, options);
}
function isCordovaApp() {
return (document.URL.indexOf('a href="http://" rel="nofollow"http:///a') === -1 && document.URL.indexOf('a href="https://" rel="nofollow"https:///a') === -1);
}
/*** Uploads a binary file (base64) using browser API, without Cordova ***/
function uploadBinaryHelper(datasource, imageBase64Data, name, type) {
Code: Select all
if (imageBase64Data) {
var byteCharacters = atob(imageBase64Data.substring(imageBase64Data.indexOf(',')+1));
var byteNumbers = new Array(byteCharacters.length);
for (var i = 0; i < byteCharacters.length; i++) {
byteNumbers[i] = byteCharacters.charCodeAt(i);
}
var byteArray = new Uint8Array(byteNumbers);
var imageType = type || 'mp3';
var imageName = name || new Date().getTime();
imageType = (imageType == 'mp3')?imageType:'mp3';
var blob = new Blob([byteArray.buffer],{type: 'video/' + imageType});
var formData = new FormData();
formData.append(imageName +'.'+ imageType, blob);
if(datasource && datasource.service) {
try {
datasource.execute({
'allowDataModification': false,
'processData': false,
'contentType':false,
'body': formData,
'cache': false
});
} catch (exception){
console.log(exception.name + ' ' + exception.message);
hideSpinner();
}
} else {
console.warn('This data source is not correct.');
}
}else{
console.warn('Image data is empty or has a wrong format.');
}
}