在HTML5中通过fileSystem API创建文件时出错代码18或22

时间:2017-06-05 11:46:34

标签: javascript html5 html5-filesystem

我在下面编写了代码来通过fileSystem API创建一个新文件,该文件出现在HTML5中:

var mywindow = window.webkitRequestFileSystem;

mywindow(window.TEMPORARY, 5 * 1024 * 1024, getFile, handleError);

function getFile(fileSystem) {
    fileSystem.root.getFile("example.txt", { create: true }, fileOpened, handleError);
}

function fileOpened(fileEntry) {
    console.log("File opened!");
    fileEntry.createWriter(writeToFile, handleError);

}

function writeToFile(fileWriter) {
    fileWriter.onwriteend = function() { alert('Success'); };
    fileWriter.onerror = function() { alert('Failed'); };
    fileWriter.write(new Blob(['Hello world'], {type: 'text/plain'}));
    }


function handleError(error) {
console.log('an error has occured ' + error.code);
}

尝试使用错误代码18调用example.txt方法创建handleError文件结果。我在代码中遗漏了哪些内容?

Google Chrome版本:58.0.3029.110(64位)

更新1 :使用--allow-file-access-from-files参数启动Google Chrome会产生相同的错误代码18。

更新2 :当我直接从磁盘浏览html文件时会导致错误代码18但是当我在IIS中的网站内托管相同的html文件时,错误代码会更改为22。 / p>

0 个答案:

没有答案