Jennifer Liu
Posts: 0
Joined: Mon Jul 28, 2014 2:09 pm

Upload Video and Transfer file to Appery IO database

Hi, I am creating an app where users can record a video and upload it onto the Appery IO database collection that I called video. However, at the moment, with my existing code, I am only able to record video, but the file does not transfer to the Appery IO database.

Here is the code that I used:
var captureSuccess = function(mediaFiles) {
var i, path, len;
for (i = 0, len = mediaFiles.length; i < len; i += 1) {
uploadVideo(mediaFiles);
}
};
// 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:1});

//"https://api.appery.io/rest/1/db/colle...",

// !! Assumes variable fileURI contains a valid URI to a text file on the device

function uploadVideo(mediaFiles){
var options = new FileUploadOptions();
options.fileKey="mediaFiles";
options.fileName=mediaFiles.substr(mediaFiles.lastIndexOf('/')+1);
options.mimeType="video/3gpp";

Code: Select all

         var ft = new FileTransfer(); 
         ft.upload(mediaFiles.fullPath, encodeURI("[url=https://api.appery.io/rest/1/db/collections/Video]https://api.appery.io/rest/1/db/colle...[/url]"), win, fail, options); 

}

function win(r) {
alert("File successfully uploaded");
}

function fail(error) {
alert("An error has occurred: Code = " + error.code);
alert("upload error source " + error.source);
alert("upload error target " + error.target);
}

I added the code to the take button:
Image

Evgene Karachevtsev
Posts: 12
Joined: Mon Apr 28, 2014 1:12 pm

Upload Video and Transfer file to Appery IO database

Hello Jennifer,

You can't upload a file to the Video collection. Files can be downloaded only in predefined collection Files.

Jennifer Liu
Posts: 0
Joined: Mon Jul 28, 2014 2:09 pm

Upload Video and Transfer file to Appery IO database

Hi there,

I have modified the code so that i uploads the file to files collection, however, it still doesn't work.

var captureSuccess = function(mediaFiles) {
var i, path, len;
for (i = 0, len = mediaFiles.length; i < len; i += 1) {
uploadVideo(mediaFiles);
}
};
// 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:1});

//"https://api.appery.io/rest/1/db/colle...",

// !! Assumes variable fileURI contains a valid URI to a text file on the device

function uploadVideo(mediaFiles){
var ft = new FileTransfer(),
path = mediaFile.fullPath,
name = mediaFile.name;

Code: Select all

     ft.upload(path, 
         "[url=https://api.appery.io/rest/1/db/files/]https://api.appery.io/rest/1/db/files/[/url]", 
         function(result) { 
             alert('Upload success: ' + result.responseCode); 
         }, 
         function(error) { 
             alert('Error uploading file ' + path + ': ' + errorThrown); 
         }, 
         { fileName: name });    

}

Evgene Karachevtsev
Posts: 12
Joined: Mon Apr 28, 2014 1:12 pm

Upload Video and Transfer file to Appery IO database

Jennifer,

We repeat our reply here:
You have an error in function uploadVideo
1) you cannot save a file in the data collection Video. Files can only be saved in predefined collection Files
2) you do not send the required headers. Please see the example here: https://getsatisfaction.com/apperyio/...

Return to “Issues”