允许在HTML5应用程序中访问Intranet /本地文件的解决方案?

问题描述:

我很清楚,即使使用新的FileAPI,也无法访问使用文件输入字段或拖放添加的文件的本地路径。这是好事,坏事还是丑陋不是问题所在。根据FileAPI规范,本地文件访问不会被实现,所以我没有屏住呼吸。

I am all too aware of the fact that even with the new FileAPI it's not possible to access the local path of a file added using a file input field or drag-and-drop. Whether or not this is good, bad or ugly is not the issue here. According to the FileAPI specs local file access is not to be implemented, and so I'm not holding my breath.

但是让我们只是假装我遇到以下固定参数:

But let's just pretend I'm in a situation with the following fixed parameters:


  • 开发HTML5应用程序只在公司内部使用

  • 用于后端的.NET(由于与API互操作而需要)

  • 可以指定/控制应该与应用程序一起使用的浏览器和版本

  • 需要访问通常位于网络共享上的文件,但也可能是本地用户工作站上的文件

  • Developing an HTML5 application only to be used internally at a company
  • .NET used for backend (needed due to interop with APIs)
  • Can specify/control exactly which browser and version should be used with the application
  • Need to access files that are usually located on a network share, but possibly also locally at a user's workstation

通过访问我不是指访问文件数据,而是能够通过向第三方提供文件的本地路径来将文件拖放/选择事件中继到其他API,以便第三方可以选择上传文件并对其进行某种处理。这可以比作使用输入[type = file]字段,就像使用.NET中的OpenFileDialog一样 - 即重点是为应用程序提供文件路径,而不是实际文件

And by access I don't mean access file data, but rather be able to relay a file drag-and-drop/select event to some other API by feeding the third party the file's local path, so that the third party can pick up the file and do some sort of work on it. This can be likened to using an input[type=file] field as you would an OpenFileDialog in .NET - i.e. the point is to feed the application a file path, not an actual file.

我意识到开箱即用这可能是不可能的。但我也认为必须有某种解决方案。

I realise that out of the box this is probably not possible. But I also think that there must be some sort of solution to the problem.

我一直在想的一些想法是:

Some ideas I've been toying with are:


  • 使用特定于浏览器的方法来允许安全功能

    • 不确定是否可能 - 使用其中一些功能累了没有可用

    • 将应用限制为特定版本的浏览器,因为将来可能会删除该功能

    • 类似Chrome扩展程序的内容可能做的伎俩


    • 可能非常混乱的解决方案

    • 最初可能会让用户感到困惑


    • 会在公司网络上发送大量文件,大小超过100 MB

    • 无法做任何事情对用户选择的文件进行就地更改

    ...和这就是它。

    任何时髦的建议?明智的话?有用的网址? Snarky评论?

    Any snazzy suggestions? Wise words? Helpful links? Snarky comments?

    谢谢。

    编辑:对于任何对此感兴趣的人,根据jgauffin的建议,使用Silverlight非常简单。

    For anyone curious about it, this was very simple using Silverlight as per jgauffin's suggestion below.

    从Silverlight代码隐藏(使用提升的权限):

    From the Silverlight codebehind (using elevated privileges):

    private void fileBtn_Click(object sender, RoutedEventArgs e)
    {
        //prompt file select dialog in Silverlight:
        var dlg = new OpenFileDialog();
        dlg.ShowDialog();
        //call JavaScript method and feed it the file path:
        HtmlPage.Window.Invoke("onFileSelected", dlg.File.FullName);
    }
    


你可能需要使用在浏览器中运行的东西,如flash或silverlight。

You'll probably have to use something that runs in the browser like flash or silverlight.

由于它是一个内部应用程序,我会使用silverlight,因为其他一切都在.NET中。应该只在插件中创建文件访问部分。

Since it's an internal app I would use silverlight as everything else is in .NET. It should be enought to only make the file access part in the plugin.

这是一篇关于本地文件访问的文章: https://www.wintellect.com/silverlight-4-s-new-local-file- system-support /

Here is an article about local file access: https://www.wintellect.com/silverlight-4-s-new-local-file-system-support/