diff --git a/src/pages/home/uploads/util.ts b/src/pages/home/uploads/util.ts index 795f1eac4..a3ac26a39 100644 --- a/src/pages/home/uploads/util.ts +++ b/src/pages/home/uploads/util.ts @@ -19,12 +19,28 @@ export const traverseFileTree = async (entry: FileSystemEntry) => { }, errorCallback) } else if (entry.isDirectory) { const dirReader = (entry as FileSystemDirectoryEntry).createReader() - dirReader.readEntries(async (entries) => { - for (let i = 0; i < entries.length; i++) { - await internalProcess(entries[i], path + entry.name + "/") - } - resolve({}) - }, errorCallback) + const readEntries = () => { + dirReader.readEntries(async (entries) => { + for (let i = 0; i < entries.length; i++) { + await internalProcess(entries[i], path + entry.name + "/") + } + resolve({}) + /** + why? https://stackoverflow.com/questions/3590058/does-html5-allow-drag-drop-upload-of-folders-or-a-folder-tree/53058574#53058574 + Unfortunately none of the existing answers are completely correct because + readEntries will not necessarily return ALL the (file or directory) entries for a given directory. + This is part of the API specification (see Documentation section below). + + To actually get all the files, we'll need to call readEntries repeatedly (for each directory we encounter) + until it returns an empty array. If we don't, we will miss some files/sub-directories in a directory + e.g. in Chrome, readEntries will only return at most 100 entries at a time. + */ + if (entries.length > 0) { + readEntries() + } + }, errorCallback) + } + readEntries() } }) await promise