我正在运行一个Flask应用程序,用户可以上传一个文件,并且必须选择网络驱动器上上传文件的根文件夹路径。此路径是IIS可用的网络路径,也是所有用户计算机上的网络驱动器。在
我想用HTML动态显示可用文件夹,即使在应用程序启动后创建了新文件夹。在
我知道由于安全原因,纯HTML无法做到这一点,但我想知道是否有办法用Flask解决这个问题。目标是使用Python将上载文件移动到choosen文件夹路径。在
我试过:
<form><input type="file" name=dir webkitdirectory directory multiple/></form>
但这只适用于Chrome。通过用户选择的路径,我可以将这个传递到Python上,将上载文件复制到那里。在
Python运行在您的服务器上,因此无法使用它来移动客户端上的文件。如果您仔细考虑一下,假设您设法(神奇地)向客户机发送python命令来移动文件,您知道他们是否安装了python来解释您的命令?在
另一方面,Javascript在客户端运行,并被用来实现这一点。然而,正如你所说,由于安全原因,现代浏览器不允许这样做。如果他们允许,那么任何网站都可能看到你的整个文件系统。在
这里有一个article解释了一点原因。查找它的文件上传控制部分。希望这能让事情更清楚一点。在
编辑:在看到您的评论后,您可以使用手术室步行. 小心,它可能很慢。在
由于现代浏览器的局限性,我决定使用JSTree作为解决方案。而且效果很好。它具有树状结构浏览器。该结构是将文件夹作为JSON输出的结果。您还可以添加搜索栏,以便用户只需键入要搜索的文件夹名。
请参见JSTree https://www.jstree.com/
如何用烧瓶实现这一点
HTML/JS:
在Flask/WTForms中调用id“folderout”。这将在用户单击文件夹时返回WTForms的路径。在
^{pr2}$使用Python创建JSON JStree文件:
相关问题 更多 >
编程相关推荐