简体   繁体   English

我可以使用 HTML5 通过单个文件拖放多个文件吗?

[英]Can I drag and drop multiple files, via a single file, using HTML5?

I have a webpage that is using HTML5's Drag and Drop API with its File API.我有一个网页使用 HTML5 的拖放 API 及其文件 API。 While simple drag and drop works well, I want to be able drag and drop a file that contains local file paths, and have those files processed as well.虽然简单的拖放效果很好,但我希望能够拖放包含本地文件路径的文件,并处理这些文件。

For instance, let's say I have a file named list.txt.例如,假设我有一个名为 list.txt 的文件。 It contains:它包含:

  • C:\users\bob\file1.txt C:\users\bob\file1.txt
  • C:\users\bob\file2.txt C:\users\bob\file2.txt
  • C:\users\alice\file3.txt C:\users\alice\file3.txt

The behavior I'm looking for is to drag and drop list.txt onto the webpage.我正在寻找的行为是将 list.txt 拖放到网页上。 As a result, the file is parsed, and each file listed within (file1.txt, file2.txt, file3.txt) is also "dropped", as if the user had manually dragged and dropped each one.结果,文件被解析,并且(file1.txt,file2.txt,file3.txt)中列出的每个文件也被“删除”,就好像用户手动拖放了每个文件一样。

Is this possible?这可能吗? If not, are there other ways for a user to do bulk drag and drop, that doesn't require manually dragging and dropping each file one at a time?如果没有,用户是否有其他方法可以进行批量拖放,而不需要一次手动拖放每个文件?

Thanks谢谢

Nope;没有; this is a security feature, to assure that your Javascript is only getting access to things specifically "granted" to it.这是一项安全功能,以确保您的 Javascript 只能访问专门“授予”它的东西。

No. The only way to achieve multiple-file drag and drop is to select multiple files and drag the group into the browser.没有。实现多文件拖放的唯一方法是select 多个文件并将组拖到浏览器中。 This only works in some browsers.这仅适用于某些浏览器。

You can try this out by dragging multiple files into gmail's attachment header.您可以通过将多个文件拖入 gmail 的附件 header 来尝试一下。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM