I have done the standard sound recording with Phonegap:
function recordSound() {
var src = "mysound.mp3";
var mediaRec = new Media(src, onSuccess, onError);
// Record audio
mediaRec.startRecord();
// Stop recording after 10 sec
var recTime = 0;
var recInterval = setInterval(function() {
recTime = recTime + 1;
setAudioPosition(recTime + " sec");
if (recTime >= 10) {
clearInterval(recInterval);
mediaRec.stopRecord();
}
}, 1000);
}
I want to now upload this file (mysound.mp3) without letting the user have to select themselves. Any help will be greatly appreciated.
So far I have done:
function win(r) {
console.log("Code = " + r.responseCode);
console.log("Response = " + r.response);
console.log("Sent = " + r.bytesSent);
}
function fail(error) {
alert("An error has occurred: Code = " + error.code);
console.log("upload error source " + error.source);
console.log("upload error target " + error.target);
}
function up() {// !! Assumes variable fileURI contains a valid URI to a text
// file on the device
var fileURI = "/mnt/sdcard/mysound.mp3";
var options = new FileUploadOptions();
options.fileKey = "file";
options.fileName=fileURI.substr(fileURI.lastIndexOf('/')+1);
options.mimeType = "audio/mp3";
var params = new Object();
params.value1 = "test";
params.value2 = "param";
options.params = params;
var ft = new FileTransfer();
ft.upload(fileURI, "http://myserver/upload.php", win, fail, options);
}
I get: java.io.IOException: Received from server
and
JSCallback Error: Request failed
Glad for the help.
You can use this function to upload the file
Hope this helps
Excellent. Really helped on ios.
Simple typo in var fail fixed below.