使用REST将图像作为流从WP8发送到WCF,没有“标题”

时间:2014-01-13 09:26:03

标签: c# wcf rest windows-phone-8

我的WP8和WFC之间有连接,我可以将图片作为流(字节数组)发送

服务方

[OperationContract]
    [WebInvoke(Method = "POST", UriTemplate = "FileUpload/{fileName}")]
    string SendImageToDB(string fileName, Stream fileStream);

SendImageToDB

public void SendSteamToDB(byte[] stream)
    {
        MySqlConnection connection = new MySqlConnection(MyconSQL);
        MySqlCommand cmd;
        connection.Open();

        try
        {
        cmd = connection.CreateCommand();
        cmd.CommandText = "UPDATE PIC SET pic_link=@image WHERE id = '1';";
        cmd.Parameters.Add("@image", MySqlDbType.Blob).Value = stream;
        cmd.ExecuteNonQuery();
        }
        catch (MySqlException ex)
        {
            Console.Write("Error: {0}", ex.ToString());
        }
        finally
        {
            if (connection != null)
            {
                connection.Close();
            }
        }
    }

Windows手机端

private void Upload_Click(object sender, EventArgs e)
    {

        string imageID = "test";
        var client = new RestClient("http://192.168.1.130:53715//Service1.svc");
        var request = new RestRequest("FileUpload/{imageName}", Method.POST);
        request.AddUrlSegment("imageName", imageID);
        request.AddFile("image/jpeg", myImage, imageID);

        client.ExecuteAsync(request, response =>
        {
        });
        try
        {
            client.ExecuteAsync(request, response =>
            {
                if (response.StatusCode == HttpStatusCode.OK)
                {
                    MessageBox.Show("Upload succes!");
                }
                else
                {
                    MessageBox.Show(response.StatusCode.ToString());
                    MessageBox.Show("Upload error!");
                }
            });
        }
        catch (Exception error)
        {
            MessageBox.Show("error" + error);
        }   
     }

所有这一切都运行正常,我在数据库中放入的字节数组只有一个问题就是某种'标题'

确实将字节数组放在.txt

enter image description here

避免这种情况的最佳方法是什么?

0 个答案:

没有答案