I'm working on a Client Application where my user authenticate against a web API made in PHP. When my user is authenticated I want to stream a blob from the MyBB database, so I can use Assembly.Load on my client and run the .exe file.
This is how I'm trying to achieve this. This is my API on the server
global $db, $encryptionEngine;
if (isset($_GET['file']) && isset($_GET['username']))
{
$username = $encryptionEngine->init($_GET['username'],"decrypt");
$query = $db->simple_select("users", "*", "LOWER(username)='".$db->escape_string(my_strtolower($username))."'", array('limit' => 1));
$user = $db->fetch_array($query);
if ($user['usergroup'] == 3 || $user['usergroup'] == 4 || $user['usergroup'] == 6 || $user['usergroup'] == 8 || $user['usergroup'] == 9)
{
$filename = $encryptionEngine->init($_GET['file'],"decrypt");
$query = $db->simple_select("files", "filecontent", "LOWER(filename)='".$db->escape_string(my_strtolower($filename))."'", array('limit' => 1));
$file = $db->fetch_array($query);
return $file['filecontent'];
}
}
filecontent on my MySQL database is the Byte[] or VarBinary. And this how I try too stream the file in my Client(C#)
public byte[] StreamFile(string file, string username)
{
using (WebClient webClient = new WebClient())
{
string address = Conversions.ToString(_authUrl + "?action=streamFile&file=" + _encryption.Encrypt(file) +"&username="+_encryption.Encrypt(username));
byte[] str = webClient.DownloadData(address);
return str;
}
}
How ever, as I'm using webClient.DownloadData it will download the whole page as a byte[] but how can I just access the VarBinary / Byte[] ?