1 回の操作で複数のファイルをディレクトリに保存しようとしています。chrome fileSystem api ドキュメントを正しく理解していれば、 chrome.fileSystem.chooseEntryにopenDirectoryオプションを使用すると、これが可能になるはずです。それも許されますか?
ただし、ドキュメントは非常に最小限であり、Google で例を見つけることもできませんでした。
詳細な背景:
ディレクトリにアクセスするための適切な権限があり、書き込み権限もあります。
/*you need chrome >= Version 31.x [currently chrome beta]*/
"permissions": [
{"fileSystem": ["write", "directory"]}, "storage",
]
次に、chrome.fileSystem.chooseEntry(object options, function callback)とchrome.fileSystem.getWritableEntry(entry entry, function callback)が残りますが、これらの関数が必要なものであるかどうかはわかりませんでした。
単一のファイルをファイル システムに保存する方法は次のとおりです。
chrome.fileSystem.chooseEntry({type:"saveFile", suggestedName:"image.jpg"},
function(entry, array){
save(entry, blob); /*the blob was provided earlier*/
}
);
function save(fileEntry, content) {
fileEntry.createWriter(function(fileWriter) {
fileWriter.onwriteend = function(e) {
fileWriter.onwriteend = null;
fileWriter.truncate(content.size);
};
fileWriter.onerror = function(e) {
console.log('Write failed: ' + e.toString());
};
var blob = new Blob([content], {'type': 'image/jpeg'});
fileWriter.write(blob);
}, errorHandler);
}
しかし、 chrome.fileSystem.chooseEntry({type:"openDirectory",..}を使用する場合、またはopenDirectoryは読み取り権限のみを付与する場合、複数のファイルを保存するにはどうすればよいですか?