1

I have implemented a app for android using phone Gap.

In the app I have two button one is Voice Enroll and another one is Voice Verification.

For Voice Enroll I implemented Record Function Using CaptureAudio in Phone Gap. It works Great.

Now I need to upload the Record file to server. I have Used Below Code.

function captureSuccess(mediaFiles) {
 var i, len;
 for (i = 0, len = mediaFiles.length; i < len; i += 1) {
alert(mediaFiles[i]);
      uploadFile(mediaFiles[i]);
 }       
}


 function captureError(error) {
 var msg = 'An error occurred during capture: ' + error.code;
 navigator.notification.alert(msg, null, 'Uh oh!');
 }


 function captureAudio() {
 navigator.device.capture.captureAudio(captureSuccess, captureError, {limit: 3);
 }

 // Upload files to server
 function uploadFile(mediaFile) {
 var ft = new FileTransfer(),
 recordingPath = mediaFile.fullPath,
 name = mediaFile.name;

 console.log('Path is: ' + recordingPath);

 ft.upload(recordingPath,
           "Webservice URL",
           function(result) {
alert("Hi");
           console.log('Upload success: ' + result.responseCode);
           console.log(result.bytesSent + ' bytes sent');
           },
           function(error) {
alert("welcome");
           console.log('Error uploading file ' + recordingPath + ': ' + error.code);
           },
           { fileName: name });   

   alert(recordingPath);
}

When I alert that mediaFiles[i] is received "Object Object". I can't receive any response after uploading.

Once Success we receive some messages from server about the audio file.

I am also send the audio file name as 'utterence'. How can i done this using phonegap and jquery mobile?

vinox
  • 401
  • 10
  • 22

1 Answers1

0

I remember having a similar problem and in my case the problem was capture returned full path and upload required the file path in different format so I had to modify the full path in a format accepted by upload.

Also make sure you set mimeType in the upload function. It defaults to image/jpeg. I am not sure how your server behaves but if it has self signed certificates then you will have to set trustAllHosts to true.

Hope this helps

Anup
  • 627
  • 5
  • 19