我有一个retainEntry用于目录,所以我可以循环它并获取FileEntry对象的列表,但我想上传这些文件,那么我可以使用FileEntry对象附加到formdata对象并上传它吗?
Menifest.json
"permissions": [
"alarms","notifications", {"fileSystem": ["write", "retainEntries", "directory"]},
"storage","http://*/*",
"https://*/*"
],
我的Action.js
var chooseDirButton = document.querySelector('#choose_dir');
var outputdir = document.querySelector('#outputdir');
chooseDirButton.addEventListener('click', function(e) {chrome.fileSystem.chooseEntry({type: 'openDirectory'}, function(theEntry) {
chrome.storage.local.set({'chosenFile': chrome.fileSystem.retainEntry(theEntry)});
loadDirEntry(theEntry)
});
});
function loadDirEntry(_chosenEntry) {
chosenEntry = _chosenEntry;
if (chosenEntry.isDirectory) {
var dirReader = chosenEntry.createReader();
var entries = [];
// Call the reader.readEntries() until no more results are returned.
var readEntries = function() {
dirReader.readEntries (function(results) {
if (!results.length) {
console.log(entries.join("\n"));
displayEntryData(chosenEntry);
}
else {
results.forEach(function(item) {
// here irem is FileEntry Object , how can i upload file using this FileEntry Object?
chrome.fileSystem.getDisplayPath(item, function(path) {
entries = entries.concat(path);
});
entries = entries.concat(item.fullPath);
});
readEntries();
}
}, errorHandler);
};
readEntries(); // Start reading dirs.
}
}
答案 0 :(得分:1)
正如@gengkev在评论中所说,使用entry.file(function(f) { ... })
提取可用于表单提交的File对象。