admin管理员组

文章数量:1391969

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:

  • Developing an HTML5 application only to be used internally at a pany
  • .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

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:

  • Using browser specific methods for allowing "secure features"
    • Not sure if possible - tired using some of these features to no avail
    • Would limit the app to a specific version of a browser as the functionality could potentially be removed in the future
    • Something like a Chrome extension could possibly do the trick
  • Using some sort of panion application installed locally on a clients puter that takes care of all on-disk file handling, possibly municating with the HTML5 client using websockets or the like.
    • A potentially pretty messy solution
    • Would probably confuse the users a bit at first
  • Submitting the selected file data to the server, storing it at specific path and sending this new path to the third party.
    • Would constitute a lot of sending files over the pany network, some 100+ MB in size
    • Would not be able to do any in-place changes to a file a user has selected

... and that's about it.

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

Thanks.

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

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);
}

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:

  • Developing an HTML5 application only to be used internally at a pany
  • .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

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:

  • Using browser specific methods for allowing "secure features"
    • Not sure if possible - tired using some of these features to no avail
    • Would limit the app to a specific version of a browser as the functionality could potentially be removed in the future
    • Something like a Chrome extension could possibly do the trick
  • Using some sort of panion application installed locally on a clients puter that takes care of all on-disk file handling, possibly municating with the HTML5 client using websockets or the like.
    • A potentially pretty messy solution
    • Would probably confuse the users a bit at first
  • Submitting the selected file data to the server, storing it at specific path and sending this new path to the third party.
    • Would constitute a lot of sending files over the pany network, some 100+ MB in size
    • Would not be able to do any in-place changes to a file a user has selected

... and that's about it.

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

Thanks.

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

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);
}
Share Improve this question edited Apr 23, 2012 at 9:34 Anders Arpi asked Apr 23, 2012 at 7:49 Anders ArpiAnders Arpi 8,4073 gold badges35 silver badges49 bronze badges 2
  • 1 chrome.google./webstore/detail/… – noob Commented Apr 23, 2012 at 8:06
  • @micha Thanks! While I don't think that solves my problem, it's a good plugin to have for this application in general. – Anders Arpi Commented Apr 23, 2012 at 8:08
Add a ment  | 

2 Answers 2

Reset to default 3

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

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.

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

does the server hosting the site have access to the network of pc's?

you could just list all the files that way.. build a small ajax script like a file dialog that will have php or whatever sending back the structure

no plugins needed, works on all browsers... :)

本文标签: javascriptSolutions to allowing intranetlocal file access in an HTML5 applicationStack Overflow