- Home /
File uploading works in editor, but not in build
Hello,
I'm trying to implement a function in my project that would save a screenshot and then send it to a pre-defined location with the WWW class. Sounds relatively simple, but it's giving me a hard time. The problem is - when I start my app in the editor, it works fine, uploads the file and everything. When I build it, however, it takes the screenshot, but doesn't upload it anymore. The WWW class throws an error "Open file error: Couldn't open file", which is vague at best. Anybody got an idea what I'm doing wrong here? Here's the code I'm using for my Screenshot Manager:
public IEnumerator TakeScreenShot(string name)
{
Debug.Log("Starting TakeScreenShot");
string fileName = name + " " + System.DateTime.Now.ToString().Replace(":", ".").Replace("/", "-") + ".png";
Debug.Log("Filename set - " + fileName);
Debug.Log("Coroutine 1 starting...");
yield return StartCoroutine("HideCam");
Debug.Log("Coroutine 1 ended.");
Debug.Log("Coroutine 2 starting...");
yield return StartCoroutine("CapScreen", fileName);
Debug.Log("Coroutine 2 ended.");
Debug.Log("Coroutine 3 starting...");
yield return StartCoroutine("ShowCam");
Debug.Log("Coroutine 3 ended.");
System.IO.FileInfo fi = new System.IO.FileInfo(fileName);
GameObject fm = GameObject.Find("FileUpload");
FileUpload uploadManager = (FileUpload)fm.GetComponent("FileUpload");
string existingFile;
existingFile = fi.FullName.Replace("\\","/");
Debug.Log("File name generated - " + existingFile);
Debug.Log("Waiting for 0.5 seconds...");
yield return new WaitForSeconds(0.5f);
Debug.Log("Wait edned. Starting upload...");
uploadManager.UploadFile(existingFile, uploadLocation);
yield return new WaitForSeconds(0.5f);
if(uploadManager.GetSuccess() == true)
fi.Delete();
yield return 1;
uploadManager.ResetSuccess();
}
For uploading I use WWW + php script combination.
Answer by barker_s · Jan 11, 2013 at 11:16 AM
Ok, I've figured it out a while ago and thought that I'd share it with you.
It seems that the culprit was FileInfo class - it kept the file from sending. As far as I was concerned it shouldn't keep a handle to the file, but removing it from the code solved my problem (had to pass the path of the file different way).
Your answer
Follow this Question
Related Questions
How to Convert MovieTexture to Byte? 1 Answer
How to upload a file from Android to my own website? 0 Answers
uploading png with wwwform 0 Answers
Returning correct result after uploading 0 Answers