drbxr86044 2016-03-20 13:38
浏览 49

来自MySQL C#/ PHP的流文件

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[] ?

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
    • ¥15 YoloV5 第三方库的版本对照问题
    • ¥15 请完成下列相关问题!
    • ¥15 drone 推送镜像时候 purge: true 推送完毕后没有删除对应的镜像,手动拷贝到服务器执行结果正确在样才能让指令自动执行成功删除对应镜像,如何解决?
    • ¥15 求daily translation(DT)偏差订正方法的代码
    • ¥15 js调用html页面需要隐藏某个按钮
    • ¥15 ads仿真结果在圆图上是怎么读数的
    • ¥20 Cotex M3的调试和程序执行方式是什么样的?
    • ¥20 java项目连接sqlserver时报ssl相关错误
    • ¥15 一道python难题3