- Home /
Can't open file when loading from WWW stream
Hi everybody,
I'm new to loading files and I'm trying this simple code to load an image into a quad as a texture. Hoever I keep getting the following error:
You are trying to load data from a www stream which had the following error when downloading. Couldn't open file C:\presentacion001.jpg
My image (named "presentacion001") is located in the root C folder. This is my code:
public IEnumerator LoadPresentation_Images() {
//different parts of the file name
string pathPrefix = @"file://";
string pathImageAssets = @"C:\";
string filename = @"presentacion001";
string fileSuffix = @".jgp";
string fullFileName = pathPrefix + pathImageAssets + filename + fileSuffix;
WWW webAccess = new WWW(fullFileName);
yield return webAccess;
Texture2D texTemp = new Texture2D(64, 64, TextureFormat.DXT1, false);
webAccess.LoadImageIntoTexture(texTemp);
presentationRenderer.material.mainTexture = texTemp;
}
I'm pretty sure my error is quite basic, but I can't seem to figure it out. Could anyone help me pinpoint it out?
Thanks!
Try this: "When using file protocol on Windows and Windows Store Apps for accessing local files, you have to specify file:/// (with three slashes)." (WWW)
Answer by Bunny83 · Nov 18, 2015 at 07:52 AM
Typo in line 6?
"jgp" should be "jpg"
Besides that like saschandroid mentioned in the comments the file scheme needs 3 slashes and not 2
Answer by ElChileVengador · Nov 18, 2015 at 11:38 PM
Thanks @saschandroid and @Bunny83 I've tried what you recommended and also changed all the slashes to '\' as that was another typo (I've actually tried both slashes), but I still get the same error message.
Also tried changing ".jpg" to ".jpeg", but to no avail.
Anything else that I could be doing wrong?
Just for FYI I tried using File.Exists and it can find the file. I've swicthed to reading all bytes and using LoadImage to get the functionality.
http://docs.unity3d.com/ScriptReference/Texture2D.LoadImage.html
However, just as a learning experience, I'd really appreciate if anyone can point me to what is wrong with my previous approach...