Cordova FileEntry可以't return文件->FILE_NOT_FOUND_ERR

Cordova FileEntry can't return File -> FILE_NOT_FOUND_ERR

本文关键字:FILE gt NOT ERR FOUND return 可以 FileEntry Cordova 文件      更新时间:2023-09-26

我正试图从iOS文件系统中获取一个文件。我的文件位于:

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

现在我正在尝试通过文件API 获取File

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);
    });
});

找到了FileEntry,但当我调用file()时,我得到了一个FileError,它看起来像这样:

[Log] FileError (main.js, line 15569)
    code: 1
    __proto__: FileError

错误代码1为:NOT_FOUND_ERR。

当找到FileEntry并且日志记录看起来正常时,为什么我会得到NOT_FOUND_ERR?

这是我的实现:

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);
});

您可以将其调整为使用您的URL。