- Home /
WWWForm.AddBinaryData() clears post and file data.
I'm making an online leaderboard and I need to be able to upload a file to be saved with the scores as well so I am using WWWForm to make a post request using AddField for the score data and AddBinaryData for the file. The request work fine without AddBinaryData but as soon as I use AddBinaryData all my post variables are gone and no files are uploaded.
WWWForm form = new WWWForm();
form.AddField("name", WWW.EscapeURL(name));
form.AddField("score", score);
string loadPath = Application.persistentDataPath + "/file.ext";
if (File.Exists(loadPath))
{
FileStream stream = new FileStream(loadPath, FileMode.Open, FileAccess.Read, FileShare.Read);
BinaryReader reader = new BinaryReader(stream);
form.AddBinaryData("file", reader.ReadBytes((int)reader.BaseStream.Length)); // 1
stream.Close();
}
WWW post = new WWW(url, form);
If I comment out the AddBinaryData line the data used by my php script is :
$_POST Array
(
[name] => NAME
[score] => 99999
)
$_FILES Array
(
)
Just by uncommenting the AddBinaryData line and doing nothing else, the data is:
$_POST Array
(
)
$FILES Array
(
)
I need to figure this out ASAP, Thanks for the help.
Answer by otis.driftwood · Dec 11, 2012 at 11:29 PM
Turns out it works fine, the problem was exceeding the file size limit.
I have the same problem, I can't uplad a 3.3mb zip file with an iPad. How much is the file limit?