Cordova FileEntry无法返回File - > FILE_NOT_FOUND_ERR

mat*_*isb 9 javascript file fileapi cordova

我试图从文件系统的iOS文件.我的文件位于:

console.log(PATH);
--> file:///var/mobile/Applications/B816F30B-791A-43E5-B33A-A26075E8B585/Documents/123123123.wav
Run Code Online (Sandbox Code Playgroud)

现在,我想获得File通过文件API

window.resolveLocalFileSystemURL(PATH, function(fileEntry){
    console.log(fileEntry.fullPath); // /var/mobile/Applications/B816F30B-791A-43E5-B33A-A26075E8B585/Documents/123123123.wav
    console.log(fileEntry.name); // 123123123.wav
    console.log(fileEntry.toURL()); cdvfile://localhost/temporary/var/mobile/Applications/B816F30B-791A-43E5-B33A-A26075E8B585/Documents/123123123.wav

    fileEntry.file(function(file){
        // do stuff
    }, function(error){
        console.log(error);
    });
});
Run Code Online (Sandbox Code Playgroud)

FileEntry被发现,但是当我打电话file(),我得到一个FileError看起来像这样:

[Log] FileError (main.js, line 15569)
    code: 1
    __proto__: FileError
Run Code Online (Sandbox Code Playgroud)

ErrorCode 1是:NOT_FOUND_ERR.

为什么在找到NOT_FOUND_ERR FileEntry并且日志记录看起来没问题时会得到它?

Mar*_*ius 0

这是我的实施:

window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, function (fs) {
    console.log('file system open: ' + fs.name);

    fs.root.getFile(fileName, {}, function (fileEntry) {
        console.log("fileEntry is file?" + fileEntry.isFile.toString());
        fileEntry.file(function (file) {
                var reader = new FileReader();
                reader.onloadend = function (evt) {
                return success(evt.target.result);
            };
            reader.readAsDataURL(file);
        });

    }, function (e) {
        throw JSON.stringify(e);
    });

}, function (e) {
    throw JSON.stringify(e);
});
Run Code Online (Sandbox Code Playgroud)

您可以调整它以使用您的 URL。