Reading a local file from webplayer. (I know it violates security but still need help)

I know unity webplayer cannot read local files. Am well aware. I am not just trying to access local files for a standard web game.

I’ve written an application that uses Unity Web Plugin as a component in an enterprise application for a company. The Unity Web Plugin is being loaded into another application through the use of a embedded web browser. So the .unity3d file and the .html file are actually stored on the local users computer.

I need to read files from the local users computer. I know I must use a workaround and Unity cannot do it directly. So I am just wondering if anyone has any suggestions about how to do this.

The application that unity and the web browser are embedded into is a C# application. So right now I succesfully have it working that unity calls a javascript function, and that javascript function calls a method in the C# application. I am planning to use this route of attack to get local files, as in have unity send the request to the containing C# application, the C# app will grab the files and then somehow deliver them back to Unity. But I am wondering, does anyone know of a better method?

I havent tested this, but I believe you might be able to use a real path instead of an URL.

So ifs its in Windows it could be C:\myapplication\start.html and c:\myapplication\app.unity3d

I would see if I was able to read from these folders. Perhaps using the c# and Directory function. If not, then see if I could build a javascript that can access these URI’s.

As you mention, the security in a webbrowser prevents this sort of action from a website, but if you are running the HTML file from the local harddrive, it might be okay to read and perhaps even write on the same “localhost”.

Havent tried it though, but interesting indeed.

Please post your findings too. :slight_smile:

You could access the filesystem via the embedded web browser, then feed the content to Unity. See:

http://unity3d.com/support/documentation/Manual/Unity%20Web%20Player%20and%20browser%20communication.html

Exactly how you do it from the embedded browser will depend on it’s details.