I’m trying to send a 60MB file up to my web server. I’m doing this by reading the file, serializing it, adding it to a WWWForm, and then using WWW to make the post:
private IEnumerable SendFile(String url, String path)
{
String fileContents = System.IO.File.ReadAllText(path);
WWWForm form = new WWWForm();
form.AddField("FileContents", fileContents);
using (WWW www = new WWW(url, form))
{
yield return www;
if (www.error == null)
{
Debug.Log("Upload successful");
}
else
{
Debug.Log(www.error);
}
}
}
This works fine for smaller files, but for my 60MB file, Unity’s memory usage shoots up to 2.6GB (from a few hundred megabytes), which sometimes causes an OutOfMemoryException to be thrown.
Why would a 60MB file consume 2.6GB of memory, and is there a better way that I could be sending this data?
Thank you.