Uploading custom filetype to MySQL database

Hiya all,

I've made a custom save file using a BinaryWriter and its various Write() methods. I now want to upload this to a MySQL database as a blob/mediumblob using a WWWForm.

I know how to upload files to a database via Unity, but how would I upload a file like this without its binary data changing when I download it again?

This is my theory ... do you think this would work?

1) Download the local file and use Convert.ToBase64String to convert bytes to string.

//Some code omitted
WWW download = new WWW(localfile);
string fileAsString  = System.Convert.ToBase64String(download.bytes);

2) Send this string to a PHP script on my server using a WWWForm.

WWWForm form = new WWWForm();
form.AddField("filedata", fileAsString);
WWW w = new WWW("http://www.mysite.com/script.php", form);

3) In the PHP script I'll insert the string into my database as a mediumblob with no encoding.

$filedata = $_POST["filedata"];
$query = "INSERT INTO myTable (file) VALUES ('$filedata');";
$sqlResult = @mysql_query($query) or die("Could not connect to database");

Will any of this change the underlying binary data?

Regards, Joel.

I've managed to answer my own question. I've managed to implement my theory above and it all works exactly how it should.

Thanks anyway everyone.