phonegap选择音频文件并将其上传到服务器上

时间:2013-12-06 06:29:58

标签: select audio cordova upload

我正在使用phonegap和jQuery mobile开发应用程序。 我想从播放列表中选择音频文件,然后将其上传到服务器上。 我有谷歌它,但没有链接显示选择音频文件,然后将其上传到服务器上, 我不想录制任何音频。 我只想在服务器上传音频(即在我的音乐文件夹或播放列表中)。 请帮帮我。

1 个答案:

答案 0 :(得分:1)

function uploadVoice(fileName, dirName, fileMime, uploadURL) {

var win = function (r) {
    console.log("Code = " + r.responseCode);
    console.log("Response = " + r.response);
    console.log("Sent = " + r.bytesSent);
};

var fail = function(error) {
    alert("An error has occurred: Code = " = error.code);
};

// file system fail
var fsFail = function(error) {
    alert("failed with error code: " + error.code);

};

var dirFail = function(error) {
    alert("Directory error code: " + error.code);

};

var fileURI;

var gotFileSystem = function (fileSystem) {
    fileSystem.root.getDirectory(dirName, {
        create: false
    }, function (dataDir) {

        fileURI = dataDir.fullPath;
        fileURI = fileURI + '/' + fileName;

        var options = new FileUploadOptions();
        options.fileKey = "file";
        options.fileName = fileURI.substr(fileURI.lastIndexOf('/') + 1);
        options.mimeType = fileMime;

        var params = new Object();
        params.value1 = "test";
        params.value2 = "param";

        options.params = params;

        var ft = new FileTransfer();
        ft.upload(fileURI, uploadURL, win, fail, options);

    }, dirFail);

};

// get file system to copy or move image file to
window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, gotFileSystem, fsFail);

}

从链接Phonegap - How can I upload an audio file after recording with Phonegap's media.startRecord

获取此信息