我正在尝试在Chrome应用中编写本地文件。
问题是我无法通过fileEntry.createWriter调用。当我调试时,一切都停在那里,控制台中没有出现任何错误。
chrome.fileSystem.chooseEntry({type: 'saveFile', suggestedName: 'myfile.html'}, function(fileEntry) {
fileEntry.createWriter(function(fileWriter) {
fileWriter.onwriteend = function(e) {
console.log('Write completed.');
};
fileWriter.onerror = function(e) {
console.log('Write failed: ' + e.toString());
};
fileWriter.write(new Blob([document.getElementById("HTMLFile").value], {type: 'text/plain'}));
}, errorHandler);
});
Chrome Ver:版本40.0.2214.28 beta(64位) 操作系统:OS X 10.10.1
答案 0 :(得分:1)
我有类似的问题。您需要在fileEntry.createWriter()调用上定义errorHandler参数。我还认为你需要将文件的MIME类型放到text / html中。
chrome.fileSystem.chooseEntry({type: 'saveFile', suggestedName:'myfile.html'}, function(fileEntry) {
fileEntry.createWriter(function(fileWriter) {
fileWriter.onwriteend = function(e) {
console.log('Write completed.');
};
fileWriter.onerror = function(e) {
console.log('Write failed: ' + e.toString());
};
fileWriter.write(new Blob([document.getElementById("HTMLFile").value], {type: 'text/html'}));
}, function(){console.warn("Your error message here");});
});