- Home /
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?
Answer by BerggreenDK · Aug 24, 2011 at 09:14 PM
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. :-)
What I am finding is that system.io is completely disabled and loading anything from www via file:// doesnt work either. So you can only get files into the web player via html://
from a security point of view, I like this. Eventhough it doesnt help your current situation. Guess you will have to build the communication around something else, as I suggested in the other question you posted about network.
BerggreenD$$anonymous$$ is saying to use the Unity WWW class, not System.IO. Cross-domain rules say that should work.
Answer by Waz · Aug 25, 2011 at 11:08 AM
You could access the filesystem via the embedded web browser, then feed the content to Unity. See:
Exactly how you do it from the embedded browser will depend on it's details.
I was going to utilize this method and I first tried this method to get data out of unity. But I found with Unity doing an Application.ExternalCall will not let you send more than 16k of data out of Unity, and getting that 16k of data out of unity is particularly slow.
I've not tried to see if I can send more than 16k into Unity, but if I can't get more than 16k out of Unity via this method I am inclined just to avoid it altogether.
Your answer
Follow this Question
Related Questions
API Compatibility Level 2 Answers
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers
WWW Request runs in Editor but not in Webplayer 1 Answer
Loading data from a different game 1 Answer