I’m saving avi gameplay videos and trying to upload them from the same standalone build.
The videos are saved to Application.dataPath folder correctly, and I can open the folder and play the videos. I can loop through the files in the directory from Unity, but I can’t load the files to attach to WWWForm to POST to the server.
IEnumerator UploadFileCo()
{
foreach (string file in System.IO.Directory.GetFiles(localFileDir))
{
txt.text = Path.GetFileName (file); //shows the correct filename
yield return new WaitForSeconds (1);
[B]//Breaks right here[/B]
WWW localFile = new WWW(file); //tries to load the file at that path
yield return localFile; //ends up loading an empty file
//The rest works it's just submitting an empty file though
WWWForm postForm = new WWWForm();
postForm.AddBinaryData("file", localFile.bytes, Path.GetFileName(file));
txt.text = localFile.bytes.Length + ""; //returns 0....
yield return new WaitForSeconds (1);
WWW upload = new WWW("www.myserver.com/VIDEOUPLOAD/addVideo.php", postForm);
yield return upload;
if (upload.error == null)
{
txt.text = ("no error: " + upload.text); //this works
}
else
{
txt.text = ("Error during upload: " + upload.error);
}
yield return new WaitForSeconds (3);
}
}
Any ideas how I can get the avi file and upload it from within a standalone build? I don’t need to view it or anything just need to push it to a server.
What is failing? Can you upload a 10-byte file to your server? How about a 1000-byte file? AVI files are generally speaking rather large, so there’s a whole bunch of places it can fail. Start small, work your way up until you have problems, and it might help you identify what is going on and come up with a solution.
He commented where it’s failing in the code “yield return localFile”
My comments stand. Can you read a 10-byte file? How about a 1000-byte file? How about a text file of the size of the AVI file you’re trying to read? If you have X bytes of available memory and you are trying to load X+1 bytes of memory, you will get an empty file.
And repeating again, you MAY have to open the file and read parts of it and send it in chunks, if there isn’t enough RAM to load an AVI file into memory.
Try the steps above and you might have a chance of figuring out where the failpoint is. If you can’t read a 10-byte file, forget about AVI files and go figure that out. If you can read a AVI-sized text file but not the AVI file, is it a DRM or permissions problem (trusted computing) that is stopping you?? You must iterate to solve a problem.
Don’t get me wrong, I thought your post was good about stepping through it. 
The way part of it was worded "Can you upload… " (later changed to “can you read”)… is what led me to respond with what I did 
For troubleshooting purpose the AVI files are small, 1mb - 1.5mb. I’m using AVPro capture to record. It’s making the files, I can open them and view them on the computer within the app’s _data folder.
I can loop through the files in the folder (Path.Combine(Application.dataPath, “Videos”)) after recording videos with the DirectoryInfo and it is listing the files and the path correctly.
Just wanted to make sure there’s nothing particular about avi files that is different from other formats that would prevent what I’m trying to do.
EDIT:: I’m debugging more, after yielding for the WWW request
WWW localFile = new WWW(file);
yield return localFile;
//txt is just a text element for debugging in builds
txt.text = localFile.size + ""; // throws error below
if I try to check the size of the file it throws an error:
Looking up that now.
Try wrapping the yield on the WWW object inside a while loop that checks for the transaction to be completed, something like:
using( WWW www = new WWW("http://www.plbm.com"))
{
while(!www.isDone)
{
yield return www;
}
// do actual stuff with your www (or file)
}
ALSO… remember that the WWW and WWWForm objects both implement the IDisposable interface, so you should ideally use them in a using() block (see above) to avoid possible lost runtime resources. The above is a website, but it works for file objects too.
1 Like