Javascript FileAPI:迭代目录?
Firefox 3.6 允许您将目录拖放到某个元素上(使用拖放 API),并使用 处理这些文件文件API。它如何与目录一起使用?
Mac OS X Finder 将某些目录显示为文件(.app、.tmbundle、.abbu 等)。在大多数情况下,这很棒。在通过 File- 和 DND-API 与浏览器交互的情况下,情况并非如此。最终用户无法区分真实文件和类似 my-addressbook-backup.abbu 的文件。
因此,Javascript UI 必须能够识别目录结构。如果它无法遍历该结构,则必须相应地通知用户。
关于如何实现其中任何一个的想法?
编辑:
我可以看到允许 JS 遍历目录时出现的(潜在)问题。我本身并不要求进行目录遍历(尽管我不要求能够这样做)。我说的是 Foo.app 被视为一个文件(如用户通过 Finder.app 看到的那样),但实际上是一个目录(如在 Terminal.app 中查看它时看到的那样)。
File API 目前不提供任何遍历机制。因此,addressbook-dump.abbu 中更深层次的嵌套文件将无法访问。有什么想法可以让这一切成为可能吗?
否则我必须告诉我的 OSX 用户将他们的地址簿文件存档(例如 ZIP)并“上传”该 zip(我实际上可以在 JS 中读取)。尽管这是一种解决方法,而不是解决方案。
Firefox 3.6 let's you drop a directory onto some element (using the Drag And Drop API) and process those files with the FileAPI. How does that work with directories?
The Mac OS X Finder displays some directories as Files (.app, .tmbundle, .abbu, …). In most cases this is wonderful. In the case of interacting with the browser via File- and DND-APIs it's not. The end-user is incapable of differentiating between a real file and a sort-of-file like my-addressbook-backup.abbu.
The Javascript UI must therefore be able to identify directory structures. If it's not capable of traversing the structure, it must inform the user accordingly.
Any ideas on how either can be accomplished?
Edit:
I can see the (potential) problems arising when allowing JS to traverse directories. I'm not calling for a directory traversal per se (although I wouldn't bind being able to). I'm talking about Foo.app being treated as a file (as so seen by the user through Finder.app) but actually being a directory (as so seen when looking at it in Terminal.app).
The File API currently doesn't provide any traversing mechanisms. So, deeper nested files within an addressbook-dump.abbu wouldn't be accessible. Are there any thoughts on making this possible?
Otherwise I'd have to tell my OSX users to make an archive (e.g. ZIP) of their address book file and "upload" that zip (which I can actually read in JS). Though this is a workaround, not a solution.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
从理论上讲,您所描述的内容可以通过 FileReader API 实现。例如,
此演示读取 .zip 文件(点击加载 photos.zip),解压其内容,并且
向用户显示其中包含的图片列表。
对于一般文件夹拖放,Chrome/WebKit 存在两个问题: 1、2。当这些问题得到解决后,您将能够将文件夹从操作系统拖到
上并遍历其所有层次结构。要查看
webkitdirectory
的实际效果,请查看 此演示在 Chrome 中。Theoretically, what you describe is doable with the
FileReader
API. For example,this demo reads a .zip file (hit load photos.zip), unpacks its contents, and
displays the list of pictures it contains to the user.
For general folder drag and drop, there are two bugs holding Chrome/WebKit back: 1, 2. When those get fixe, you'll be able to drag a folder from the OS onto an
<input type="file" webkitdirectory>
and traverse all its hierarchy. To seewebkitdirectory
in action, check out this demo in Chrome.