在用户进行选择后,files 里的每个 File 对象都会将其 File.webkitRelativePath 属性设置为所选目录内文件所在的相对路径。例如,考虑以下文件系统:
PhotoAlbums
Birthdays
Jamie's 1st birthday
PIC1000.jpg
PIC1004.jpg
PIC1044.jpg
Don's 40th birthday
PIC2343.jpg
PIC2344.jpg
PIC2355.jpg
PIC2356.jpg
Vacations
Mars
PIC5533.jpg
PIC5534.jpg
PIC5556.jpg
PIC5684.jpg
PIC5712.jpg
如果用户选择了 PhotoAlbums,则文件列表上将会包含上面列出的每个文件(而不包含目录)的 File 对象。条目 PIC2343.jpg 的 webkitRelativePath 属性值将会是 PhotoAlbums/Birthdays/Don's 40th birthday/PIC2343.jpg。即使 FileList 是扁平的,这也使得知道层次结构成为可能。
备注: 在 Chromium < 72 的版本中,webkitRelativePath 的行为表现有所不同。有关更多详细信息,请参见此 bug。
|