简体   繁体   English

解决Html5本地文件访问

[英]Work around for Html5 Local File Access

We are currently looking at porting a enterprise silverlight application over to html5. 我们目前正在考虑将企业Silverlight应用程序移植到html5。 The major roadblock that we have hit is the ability to open files from the user's local disk. 我们遇到的主要障碍是能够从用户的本地磁盘打开文件。 Currently they have a document library which just links to files on their computer that they can open from within the app and view or print out. 目前,他们有一个文档库,它们仅链接到计算机上的文件,可以从应用程序内打开它们并查看或打印出来。 All that I read is that you can only access the local sandbox of the web app with the html5 file api's. 我读到的所有内容是,您只能使用html5文件api访问Web应用程序的本地沙箱。 We want to load these files from code. 我们要从代码加载这些文件。

Does anyone know of any workarounds to this? 有人知道任何解决方法吗?

Thanks 谢谢

There is no way for html5 to access local file without user selection. 没有用户选择,html5无法访问本地文件。 But FSO: FileSystemObject works for IE and MAYBE could be regarded as a work around. 但是FSO:FileSystemObject适用于IE,可以认为MAYBE可以解决。 But still there are some requirements to meet. 但是仍然需要满足一些要求。

It is possible to use chrome's filesystem API to access files on a users local filesytem. 可以使用chrome的文件系统API访问用户本地文件系统上的文件。 So you'd have to be willing to make this a chrome only application. 因此,您必须愿意使它成为仅适用于Chrome的应用程序。

Using java you can create a "Signed" applet which has access to the local filesystem. 使用Java,您可以创建一个“签名”小程序,该小程序可以访问本地文件系统。 (if the applet is signed you can request filesystm permissions) (如果小程序已签名,则可以请求filesystm权限)

then there is a tutorial for accessing methods of your java code directly from javascript here: http://docs.oracle.com/javase/tutorial/deployment/applet/invokingAppletMethodsFromJavaScript.html 然后这里有直接从javascript直接访问Java代码方法的教程: http : //docs.oracle.com/javase/tutorial/deployment/applet/invokingAppletMethodsFromJavaScript.html

you should be able to perform something similar from silverlight. 您应该能够执行与Silverlight类似的操作。

There is no workaround in pure HTML5/Javascript. 在纯HTML5 / Javascript中没有解决方法。 You need the use of plugins, such as Java or Silverlight (maybe you shouldn't port it after all). 您需要使用Java或Silverlight之类的插件(也许您根本不应该移植它)。 As for workarounds, HTML5 gives you an easy way drag and drop multiple files that you could transfer on the server and then display back to your users. 至于解决方法,HTML5为您提供了一种简单的方法,可以拖放多个文件,这些文件可以在服务器上传输,然后显示回给用户。 Another workaround would be to install a custom agent (a software with only a tray icon) that would send the information about the current user "document library" to server and then again, you could display it back to the user. 另一个解决方法是安装自定义代理(仅带有托盘图标的软件),该代理会将有关当前用户“文档库”的信息发送到服务器,然后再次将其显示给用户。

Note: I've heard somewhere that browsers will eventually stop supporting plugins. 注意:我听说某处浏览器最终将停止支持插件。 http://www.howtogeek.com/179213/why-browser-plug-ins-are-going-away-and-whats-replacing-them/ http://www.howtogeek.com/179213/why-browser-plug-ins-are-going-away-and-whats-replacing-them/

Ya, I agree with Markain. 是的,我同意Markain。 However, if you were to limit your audience solely to chrome users, I daresay, you would most likely use some of your users. 但是,我敢说,如果您仅将受众群体限制为Chrome用户,则很可能会使用某些用户。 If Huazhihao is right, then your number of leaving customers should decrease but users who regularly use firefox won't be happy. 如果Huazhihao是正确的,那么您的离开客户的数量应该减少,但是经常使用firefox的用户将不会满意。 Overall, I think that this will not work. 总的来说,我认为这是行不通的。 Otherwise, there would be too many websites that trashed your hard driver (or at least wherever you have the rights to edit/delete files). 否则,将会有太多网站浪费您的硬盘驱动器(或者至少在您有权编辑/删除文件的位置)。 I think it would be best if your product was setup to synchronize the file whenever an internet connection was detected and a change was made to the file. 我认为最好是将您的产品设置为在检测到Internet连接并且对该文件进行更改时同步该文件。 That way the user would not need to visit the website whenever the file was uploaded. 这样,只要上传文件,用户就无需访问网站。 If this is some kind of an error file, then it would be most beneficial if you were to make a link in the application that when clicked, would upload the file to the website and the website were to do whatever was necessary. 如果这是某种错误文件,那么如果您在应用程序中创建一个链接,该链接将在单击后将文件上传到网站,并且网站将做任何必要的事情,这将是最有益的。 If this is a purely online thing, then I don't see what business you would have looking through other peoples' files =-). 如果这纯粹是在线活动,那么我看不到您希望通过其他人的文件来查找什么业务=-)。 Hope I helped! 希望我能帮上忙!

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

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