Record and upload audio file to server

Hello im trying to make an app that records audio when you press a button, and then send it to nuance for ASR.

So far i am just trying to upload it to my own local host for testing how ever i cant seem to get the file uploaded.

I am using an android 4.4.2 tablet for testing.
File has been recorded and can be found on the tablet when connected to the computer, but not in an folder for the app (No clue if thats important or not)

I hope someone can help me figure this out

Controller:

.controller('MainCtrl', function ($scope, $cordovaFileTransfer) {
    var src = "myrecording.amr";
    document.addEventListener("deviceready", onDeviceReady, false);
    function onDeviceReady() {
        console.log(Media);
    }
    // play audio
    $scope.PlayAudio = function () {
        console.log("try to start music");
        // Play the audio file at url
        var my_media = new Media(src,
            // success callback
            function () {
                console.log("playAudio():Audio Success");
            },
            // error callback
            function (err) {
                console.log("playAudio():Audio Error: " + err);
            }
        );
        // Play audio
        my_media.play();
    }
// Record audio
//
$scope.RecordAudio = function () {
    console.log("Records");
    var mediaRec = new Media(src,
        // success callback
        function () {
            console.log("recordAudio():Audio Success");
        },

        // error callback
        function (err) {
            console.log("recordAudio():Audio Error: " + JSON.stringify(err.code));
        }
    );

    // Record audio
    mediaRec.startRecord();

    // Stop recording after 10 seconds
    setTimeout(function () {
        mediaRec.stopRecord();
        console.log("Stop recording");
    }, 10000);
}
$scope.SendAudio = function () {
    var options = {
        fileKey: "fileToUpload",
        fileName: "myrecording.amr",
        chunkedMode: false,
        mimeType: "audio/AMR",
        httpMethod: "post"
    };
    $cordovaFileTransfer.upload("http://172.30.1.206/test/asr/post.php", src, options).then(function (result) {
        console.log("SUCCESS: " + JSON.stringify(result));
    }, function (err) {
        console.log("ERROR: " + JSON.stringify(err));
    }, function (progress) {
        // constant progress updates
    });
}
})

ERROR:

{"code":1,"source":"myrecording.amr","target":"http://172.30.1.206/test/asr/post.php","http_status":200,"body":null,"exception":"/myrecording.amr: open failed: ENOENT (No such file or directory)"} 

PHP:

<?php
//header('content-type: application/json; charset=utf-8');
header('Access-Control-Allow-Origin: *');
$target_dir = "sound/";
$target_file = $target_dir . basename($_FILES["fileToUpload"]["name"]);
$imageFileType = pathinfo($target_file,PATHINFO_EXTENSION);
$response = array();
$response['success'] = 1;
// Check if image file is a actual image or fake image
// Check if file already exists
if (file_exists($target_file)) {
    echo "Sorry, file already exists.";
    $response['success'] = 0;
}
// Check file size
if ($_FILES["fileToUpload"]["size"] > 500000) {
    echo "Sorry, your file is too large.";
    $response['success'] = 0;
}
// Check if $uploadOk is set to 0 by an error
if ($uploadOk == 0) {
    $response['errorMsg'] = "Sorry, your file was not uploaded.";
// if everything is ok, try to upload file
} else {
    if (move_uploaded_file($_FILES["fileToUpload"]["tmp_name"], $target_file)) {
        $response['successMsg'] = "The file ". basename( $_FILES["fileToUpload"]["name"]). " has been uploaded.";
    } else {
        $response['successMsg'] = "Sorry, there was an error uploading your file.";
    }
}

if (isset($_GET['callback'])) {
    echo $_GET['callback'] . '('.json_encode($response).')';
} else {   
    echo json_encode($response,JSON_PRETTY_PRINT);
}
?>

No one whos able to help?
Am i really to give up on this wonderfull framework for this app?

Hey Mathias Where you able to Solve this Issue ?

Hello Donsplash,
No sadly not, i didnt have enought time to keep trying, so i ended up making an native app

hello Mathias
My problem is that i am not into Native Apps and i need to upload sound files in my App i am Stock its so painful i dont know what to do.

I am afraid that i cant help you

Dear mathiasRobinson ,

Please find the below one it worked for me :grinning:
ANGULAR CODE***************************
var options = {
fileKey: “fileToUpload”,
fileName: name,
chunkedMode: false,
mimeType: “audio/m4a”,
httpMethod: “post”
};
$cordovaFileTransfer.upload(“http://xxxxxxxx/Audio/Upload.php”, path, options)
.then(function (result) {
alert("SUCCESS: " + JSON.stringify(result));
}, function (err) {
alert("ERROR: " + JSON.stringify(err));
}, function (progress) {
// constant progress updates
});
*********************************PHP FILE *************************************************************************

<?php //header('content-type: application/json; charset=utf-8'); header('Access-Control-Allow-Origin: *'); $target_dir = "/home/xxxxxxxxxxxx/public_html/Audio/Upload.php"; $target_file = $target_dir . basename($_FILES["fileToUpload"]["name"]); $uploadOk = 1; //$target_file = ; $imageFileType = pathinfo($target_file,PATHINFO_EXTENSION); $response = array(); $response['success'] = 1; // Check if image file is a actual image or fake image // Check if file already exists if (file_exists($target_file)) { echo "Sorry, file already exists."; $response['success'] = 0; } // Check file size if ($_FILES["fileToUpload"]["size"] > 500000) { echo "Sorry, your file is too large."; $response['success'] = 0; } // Check if $uploadOk is set to 0 by an error if ($uploadOk == 0) { $response['errorMsg'] = "Sorry, your file was not uploaded."; // if everything is ok, try to upload file } else { if (move_uploaded_file($_FILES["fileToUpload"]["tmp_name"], $target_file)) { $response['successMsg'] = "The file ". basename( $_FILES["fileToUpload"]["name"]). " has been uploaded."; } else { $response['successMsg'] = "Sorry, there was an error uploading your file."; } } if (isset($_GET['callback'])) { echo $_GET['callback'] . '('.json_encode($response).')'; } else { echo json_encode($response,JSON_PRETTY_PRINT); } ?>