【问题标题】:How to access audio fle and upload to server in phonegap如何在phonegap中访问音频文件并上传到服务器
【发布时间】:2014-04-08 22:17:46
【问题描述】:

我有一个查询,比如我想访问手机间隙 ios 中的所有音频文件并想上传到服务器,所以任何人都知道如何获取所有 mp3 文件并上传。 我们应该为此创建一个插件。

【问题讨论】:

标签: javascript ios cordova


【解决方案1】:

我认为您不需要创建新插件。现有的文件和文件传输 API 应该适用于您的情况,除非您有除此处所述之外的更多要求。

使用文件 API 迭代应用中的所有文件。

function success(entries) {
    var i;
    for (i=0; i<entries.length; i++) {
        console.log(entries[i].name);
           //Check if the file is in mp3 format. If it is in mp3 format, trigger file upload.

    }
}

function fail(error) {
    alert("Failed to list directory contents: " + error.code);
}

// Get a directory reader
var directoryReader = dirEntry.createReader();

// Get a list of all the entries in the directory
directoryReader.readEntries(success,fail); 

然后使用文件上传API将文件上传到服务器。

var ft = new FileTransfer();
ft.upload(fileURI, encodeURI("http://some.server.com/upload.php"), win, fail, options);

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-06-07
    • 2014-04-26
    • 2015-11-25
    相关资源
    最近更新 更多